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.
feat(backend): Immediate alert on late execution check job failure (#9925)
Zamil Majdye8bc83445a33
diff --git a/autogpt_platform/backend/backend/executor/scheduler.py b/autogpt_platform/backend/backend/executor/scheduler.pyindex 8f0f258f7b..05ce759b3b 100644--- a/autogpt_platform/backend/backend/executor/scheduler.py+++ b/autogpt_platform/backend/backend/executor/scheduler.py@@ -20,7 +20,7 @@ from backend.data.block import BlockInputfrom backend.data.execution import ExecutionStatusfrom backend.executor import utils as execution_utilsfrom backend.notifications.notifications import NotificationManagerClient-from backend.util.metrics import sentry_alert+from backend.util.metrics import discord_send_alert, sentry_capture_errorfrom backend.util.service import (AppService,AppServiceClient,@@ -110,9 +110,10 @@ def report_late_executions() -> str:f"Graph has been queued for more than {config.execution_late_notification_threshold_secs} seconds. ""Please check the executor status.")- logger.error(error)- sentry_alert(error)- return str(error)+ msg = str(error)+ sentry_capture_error(error)+ discord_send_alert(msg)+ return msgdef process_existing_batches(**kwargs):diff --git a/autogpt_platform/backend/backend/util/metrics.py b/autogpt_platform/backend/backend/util/metrics.pyindex eba9068043..3e1822fad0 100644--- a/autogpt_platform/backend/backend/util/metrics.py+++ b/autogpt_platform/backend/backend/util/metrics.py@@ -1,6 +1,8 @@+import asyncioimport loggingimport sentry_sdk+from pydantic import SecretStrfrom sentry_sdk.integrations.anthropic import AnthropicIntegrationfrom sentry_sdk.integrations.logging import LoggingIntegration@@ -24,6 +26,41 @@ def sentry_init():)-def sentry_alert(error: Exception):+def sentry_capture_error(error: Exception):sentry_sdk.capture_exception(error)sentry_sdk.flush()+++def discord_send_alert(content: str):+ from backend.blocks.discord import SendDiscordMessageBlock+ from backend.data.model import APIKeyCredentials, CredentialsMetaInput, ProviderName+ from backend.util.settings import Settings++ settings = Settings()+ creds = APIKeyCredentials(+ provider="discord",+ api_key=SecretStr(settings.secrets.discord_bot_token),+ title="Provide Discord Bot Token for the platform alert",+ expires_at=None,+ )++ try:+ loop = asyncio.get_event_loop()+ except RuntimeError:+ loop = asyncio.new_event_loop()+ asyncio.set_event_loop(loop)++ return SendDiscordMessageBlock().run_once(+ SendDiscordMessageBlock.Input(+ credentials=CredentialsMetaInput(+ id=creds.id,+ title=creds.title,+ type=creds.type,+ provider=ProviderName.DISCORD,+ ),+ message_content=content,+ channel_name=settings.config.platform_alert_discord_channel,+ ),+ "status",+ credentials=creds,+ )diff --git a/autogpt_platform/backend/backend/util/settings.py b/autogpt_platform/backend/backend/util/settings.pyindex 31bae11fbc..159e31bb88 100644--- a/autogpt_platform/backend/backend/util/settings.py+++ b/autogpt_platform/backend/backend/util/settings.py@@ -239,6 +239,10 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):default=True,description="Whether to enable the agent input subtype blocks",)+ platform_alert_discord_channel: str = Field(+ default="local-alerts",+ description="The Discord channel for the platform",+ )@field_validator("platform_base_url", "frontend_base_url")@classmethod