main
py 29 lines 1.15 KB
Raw
1 from helpers.api import ApiHandler, Input, Output, Request
2 from helpers.task_scheduler import TaskScheduler
3 import traceback
4 from helpers.print_style import PrintStyle
5 from helpers.localization import Localization
6
7
8 class SchedulerTasksList(ApiHandler):
9 async def process(self, input: Input, request: Request) -> Output:
10 """
11 List all tasks in the scheduler with their types
12 """
13 try:
14 # Get timezone from input (do not set if not provided, we then rely on poll() to set it)
15 if timezone := input.get("timezone", None):
16 Localization.get().set_timezone(timezone)
17
18 # Get task scheduler
19 scheduler = TaskScheduler.get()
20 await scheduler.reload()
21
22 # Use the scheduler's convenience method for task serialization
23 tasks_list = scheduler.serialize_all_tasks()
24
25 return {"ok": True, "tasks": tasks_list}
26
27 except Exception as e:
28 PrintStyle.error(f"Failed to list tasks: {str(e)} {traceback.format_exc()}")
29 return {"ok": False, "error": f"Failed to list tasks: {str(e)} {traceback.format_exc()}", "tasks": []}