Scheduler: use convenience methods for logging of special messages
Rafael Uzarowski committed
Nov 19, 2025 at 13:00 UTC
51c8451696ac52e43864a535d173a502cfe13b67
1 file changed
+23
-23
python/helpers/task_scheduler.py
+23
-23
@@ -215,7 +215,7 @@ class BaseTask(BaseModel):
215
last_result=f"ERROR: {error}"
216
)
217
if not updated_task:
218
- PrintStyle(italic=True, font_color="red", padding=False).print(
218
+ PrintStyle.error(
219
f"Failed to update task {self.uuid} state to ERROR after error: {error}"
220
)
221
await scheduler.save() # Force save after update
@@ -231,7 +231,7 @@ class BaseTask(BaseModel):
231
last_result=result
232
)
233
if not updated_task:
234
- PrintStyle(italic=True, font_color="red", padding=False).print(
234
+ PrintStyle.error(
235
f"Failed to update task {self.uuid} state to IDLE after success"
236
)
237
await scheduler.save() # Force save after update
@@ -504,12 +504,12 @@ class SchedulerTaskList(BaseModel):
504
for task in self.tasks:
505
if isinstance(task, AdHocTask):
506
if task.token is None or task.token == "":
507
- PrintStyle(italic=True, font_color="red", padding=False).print(
507
+ PrintStyle.warning(
508
f"WARNING: AdHocTask {task.name} ({task.uuid}) has a null or empty token before saving: '{task.token}'"
509
)
510
# Generate a new token to prevent errors
511
task.token = str(random.randint(1000000000000000000, 9999999999999999999))
512
- PrintStyle(italic=True, font_color="red", padding=False).print(
512
+ PrintStyle.info(
513
f"Fixed: Generated new token '{task.token}' for task {task.name}"
514
)
515
@@ -522,7 +522,7 @@ class SchedulerTaskList(BaseModel):
522
523
# Debug: check if 'null' appears as token value in JSON
524
if '"type": "adhoc"' in json_data and '"token": null' in json_data:
525
- PrintStyle(italic=True, font_color="red", padding=False).print(
525
+ PrintStyle.error(
526
"ERROR: Found null token in JSON output for an adhoc task"
527
)
528
@@ -532,7 +532,7 @@ class SchedulerTaskList(BaseModel):
532
if exists(path):
533
loaded_json = read_file(path)
534
if '"type": "adhoc"' in loaded_json and '"token": null' in loaded_json:
535
- PrintStyle(italic=True, font_color="red", padding=False).print(
535
+ PrintStyle.error(
536
"ERROR: Null token persisted in JSON file for an adhoc task"
537
)
538
@@ -650,7 +650,7 @@ class TaskScheduler:
650
deferred_task = self._running_deferred_tasks.get(task_uuid)
651
if not deferred_task:
652
return False
653
- self._printer.print(f"Scheduler cancelling task {task_uuid}")
653
+ PrintStyle.info(f"Scheduler cancelling task {task_uuid}")
654
deferred_task.kill(terminate_thread=terminate_thread)
655
return True
656
@@ -719,7 +719,7 @@ class TaskScheduler:
719
720
# If the task is in error state, reset it to IDLE first
721
if task.state == TaskState.ERROR:
722
- self._printer.print(f"Resetting task '{task.name}' from ERROR to IDLE state before running")
722
+ PrintStyle.info(f"Resetting task '{task.name}' from ERROR to IDLE state before running")
723
await self.update_task(task_uuid, state=TaskState.IDLE)
724
# Force a reload to ensure we have the updated state
725
await self._tasks.reload()
@@ -782,13 +782,13 @@ class TaskScheduler:
782
783
if context:
784
assert isinstance(context, AgentContext)
785
- self._printer.print(
785
+ PrintStyle.info(
786
f"Scheduler Task {task.name} loaded from task {task.uuid}, context ok"
787
)
788
save_tmp_chat(context)
789
return context
790
else:
791
- self._printer.print(
791
+ PrintStyle.warning(
792
f"Scheduler Task {task.name} loaded from task {task.uuid} but context not found"
793
)
794
return await self.__new_context(task)
@@ -805,23 +805,23 @@ class TaskScheduler:
805
# preflight checks with a snapshot of the task
806
task_snapshot: Union[ScheduledTask, AdHocTask, PlannedTask] | None = self.get_task_by_uuid(task_uuid)
807
if task_snapshot is None:
808
- self._printer.print(f"Scheduler Task with UUID '{task_uuid}' not found")
808
+ PrintStyle.error(f"Scheduler Task with UUID '{task_uuid}' not found")
809
self._unregister_running_task(task_uuid)
810
return
811
if task_snapshot.state == TaskState.RUNNING:
812
- self._printer.print(f"Scheduler Task '{task_snapshot.name}' already running, skipping")
812
+ PrintStyle.warning(f"Scheduler Task '{task_snapshot.name}' already running, skipping")
813
self._unregister_running_task(task_uuid)
814
return
815
816
# Atomically fetch and check the task's current state
817
current_task = await self.update_task_checked(task_uuid, lambda task: task.state != TaskState.RUNNING, state=TaskState.RUNNING)
818
if not current_task:
819
- self._printer.print(f"Scheduler Task with UUID '{task_uuid}' not found or updated by another process")
819
+ PrintStyle.error(f"Scheduler Task with UUID '{task_uuid}' not found or updated by another process")
820
self._unregister_running_task(task_uuid)
821
return
822
if current_task.state != TaskState.RUNNING:
823
# This means the update failed due to state conflict
824
- self._printer.print(f"Scheduler Task '{current_task.name}' state is '{current_task.state}', skipping")
824
+ PrintStyle.warning(f"Scheduler Task '{current_task.name}' state is '{current_task.state}', skipping")
825
self._unregister_running_task(task_uuid)
826
return
827
@@ -831,7 +831,7 @@ class TaskScheduler:
831
agent = None
832
833
try:
834
- self._printer.print(f"Scheduler Task '{current_task.name}' started")
834
+ PrintStyle.info(f"Scheduler Task '{current_task.name}' started")
835
836
context = await self._get_chat_context(current_task)
837
AgentContext.use(context.id)
@@ -854,9 +854,9 @@ class TaskScheduler:
854
if url.scheme in ["http", "https", "ftp", "ftps", "sftp"]:
855
attachment_filenames.append(attachment)
856
else:
857
- self._printer.print(f"Skipping attachment: [{attachment}]")
857
+ PrintStyle.warning(f"Skipping attachment: [{attachment}]")
858
except Exception:
859
- self._printer.print(f"Skipping attachment: [{attachment}]")
859
+ PrintStyle.warning(f"Skipping attachment: [{attachment}]")
860
861
self._printer.print("User message:")
862
self._printer.print(f"> {current_task.prompt}")
@@ -893,7 +893,7 @@ class TaskScheduler:
893
result = await agent.monologue()
894
895
# Success
896
- self._printer.print(f"Scheduler Task '{current_task.name}' completed: {result}")
896
+ PrintStyle.success(f"Scheduler Task '{current_task.name}' completed: {result}")
897
await self._persist_chat(current_task, context)
898
await current_task.on_success(result)
899
@@ -901,11 +901,11 @@ class TaskScheduler:
901
await self._tasks.reload()
902
updated_task = self.get_task_by_uuid(task_uuid)
903
if updated_task and updated_task.state != TaskState.IDLE:
904
- self._printer.print(f"Fixing task state consistency: '{current_task.name}' state is not IDLE after success")
904
+ PrintStyle.warning(f"Fixing task state consistency: '{current_task.name}' state is not IDLE after success")
905
await self.update_task(task_uuid, state=TaskState.IDLE)
906
907
except asyncio.CancelledError:
908
- self._printer.print(f"Scheduler Task '{current_task.name}' cancelled by user")
908
+ PrintStyle.warning(f"Scheduler Task '{current_task.name}' cancelled by user")
909
try:
910
await asyncio.shield(self.update_task(task_uuid, state=TaskState.IDLE))
911
except Exception:
@@ -913,14 +913,14 @@ class TaskScheduler:
913
raise
914
except Exception as e:
915
# Error
916
- self._printer.print(f"Scheduler Task '{current_task.name}' failed: {e}")
916
+ PrintStyle.error(f"Scheduler Task '{current_task.name}' failed: {e}")
917
await current_task.on_error(str(e))
918
919
# Explicitly verify task was updated in storage after error
920
await self._tasks.reload()
921
updated_task = self.get_task_by_uuid(task_uuid)
922
if updated_task and updated_task.state != TaskState.ERROR:
923
- self._printer.print(f"Fixing task state consistency: '{current_task.name}' state is not ERROR after failure")
923
+ PrintStyle.warning(f"Fixing task state consistency: '{current_task.name}' state is not ERROR after failure")
924
await self.update_task(task_uuid, state=TaskState.ERROR)
925
926
if agent:
@@ -1094,7 +1094,7 @@ def parse_task_plan(plan_data: Dict[str, Any]) -> TaskPlan:
1094
done=done_dates_cast
1095
)
1096
except Exception as e:
1097
- PrintStyle(italic=True, font_color="red", padding=False).print(
1097
+ PrintStyle.error(
1098
f"Error parsing task plan: {e}"
1099
)
1100
# Return empty plan instead of failing