From 4923318cfe0f3ddaaa0b8bda800fdec2534dc674 Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Tue, 17 Jun 2025 10:20:17 -0700 Subject: [PATCH] fix(backend): Fix scheduler ayncio loop issue & update late execution message report --- .../backend/backend/executor/scheduler.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/autogpt_platform/backend/backend/executor/scheduler.py b/autogpt_platform/backend/backend/executor/scheduler.py index acb3aa481f..a3414db339 100644 --- a/autogpt_platform/backend/backend/executor/scheduler.py +++ b/autogpt_platform/backend/backend/executor/scheduler.py @@ -72,8 +72,13 @@ def get_notification_client(): return get_service_client(NotificationManagerClient) +@thread_cached +def get_event_loop(): + return asyncio.new_event_loop() + + def execute_graph(**kwargs): - asyncio.run(_execute_graph(**kwargs)) + get_event_loop().run_until_complete(_execute_graph(**kwargs)) async def _execute_graph(**kwargs): @@ -110,11 +115,17 @@ def report_late_executions() -> str: num_late_executions = len(late_executions) num_users = len(set([r.user_id for r in late_executions])) + + late_execution_details = [ + f"* `Execution ID: {exec.id}, Graph ID: {exec.graph_id}v{exec.graph_version}, User ID: {exec.user_id}, Created At: {exec.started_at.isoformat()}`" + for exec in late_executions + ] + error = LateExecutionException( f"Late executions detected: {num_late_executions} late executions from {num_users} users " f"in the last {config.execution_late_notification_checkrange_secs} seconds. " f"Graph has been queued for more than {config.execution_late_notification_threshold_secs} seconds. " - "Please check the executor status." + f"Please check the executor status. Details:\n{'\n'.join(late_execution_details)}" ) msg = str(error) sentry_capture_error(error)