Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(backend): Fix scheduler ayncio loop issue & update late execution message report

Zamil Majdy4923318cfe0f
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)