feat: make command parameter optional in set_alarm mutation
This commit is contained in:
+16
-4
@@ -1,12 +1,16 @@
|
||||
import strawberry
|
||||
from typing import List, Optional
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from api.crontab_manager import CrontabManager
|
||||
|
||||
|
||||
def get_manager():
|
||||
tabfile = os.getenv("TABFILE")
|
||||
return CrontabManager(tabfile=tabfile)
|
||||
|
||||
|
||||
@strawberry.type
|
||||
class Alarm:
|
||||
id: str
|
||||
@@ -14,6 +18,7 @@ class Alarm:
|
||||
command: str
|
||||
is_enabled: bool
|
||||
|
||||
|
||||
@strawberry.type
|
||||
class Query:
|
||||
@strawberry.field
|
||||
@@ -30,28 +35,34 @@ class Query:
|
||||
return Alarm(**a)
|
||||
return None
|
||||
|
||||
|
||||
@strawberry.type
|
||||
class Mutation:
|
||||
@strawberry.field
|
||||
def set_alarm(
|
||||
self,
|
||||
cron_expression: str,
|
||||
command: str,
|
||||
command: Optional[str] = None,
|
||||
is_enabled: bool = True,
|
||||
id: Optional[str] = None
|
||||
id: Optional[str] = None,
|
||||
) -> Alarm:
|
||||
if command is None:
|
||||
project_root = Path(__file__).parent.parent.absolute()
|
||||
python_exec = sys.executable
|
||||
command = f"cd {project_root} && {python_exec} wecker.py > wecker.log 2>&1"
|
||||
|
||||
manager = get_manager()
|
||||
new_id = manager.set_alarm(
|
||||
alarm_id=id,
|
||||
cron_expression=cron_expression,
|
||||
command=command,
|
||||
is_enabled=is_enabled
|
||||
is_enabled=is_enabled,
|
||||
)
|
||||
return Alarm(
|
||||
id=new_id,
|
||||
cron_expression=cron_expression,
|
||||
command=command,
|
||||
is_enabled=is_enabled
|
||||
is_enabled=is_enabled,
|
||||
)
|
||||
|
||||
@strawberry.field
|
||||
@@ -65,4 +76,5 @@ class Mutation:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
schema = strawberry.Schema(query=Query, mutation=Mutation)
|
||||
|
||||
Reference in New Issue
Block a user