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(scheduler): route db calls through DatabaseManager (#11941)
Ottoaef6f57cfd5f
diff --git a/autogpt_platform/backend/backend/executor/database.py b/autogpt_platform/backend/backend/executor/database.pyindex ae7474fc1d..d44439d51c 100644--- a/autogpt_platform/backend/backend/executor/database.py+++ b/autogpt_platform/backend/backend/executor/database.py@@ -17,6 +17,7 @@ from backend.data.analytics import (get_accuracy_trends_and_alerts,get_marketplace_graphs_for_monitoring,)+from backend.data.auth.oauth import cleanup_expired_oauth_tokensfrom backend.data.credit import UsageTransactionMetadata, get_user_credit_modelfrom backend.data.execution import (create_graph_execution,@@ -219,6 +220,9 @@ class DatabaseManager(AppService):# Onboardingincrement_onboarding_runs = _(increment_onboarding_runs)+ # OAuth+ cleanup_expired_oauth_tokens = _(cleanup_expired_oauth_tokens)+# Storeget_store_agents = _(get_store_agents)get_store_agent_details = _(get_store_agent_details)@@ -349,6 +353,9 @@ class DatabaseManagerAsyncClient(AppServiceClient):# Onboardingincrement_onboarding_runs = d.increment_onboarding_runs+ # OAuth+ cleanup_expired_oauth_tokens = d.cleanup_expired_oauth_tokens+# Storeget_store_agents = d.get_store_agentsget_store_agent_details = d.get_store_agent_detailsdiff --git a/autogpt_platform/backend/backend/executor/scheduler.py b/autogpt_platform/backend/backend/executor/scheduler.pyindex 44b77fc018..cbdc441718 100644--- a/autogpt_platform/backend/backend/executor/scheduler.py+++ b/autogpt_platform/backend/backend/executor/scheduler.py@@ -24,11 +24,9 @@ from dotenv import load_dotenvfrom pydantic import BaseModel, Field, ValidationErrorfrom sqlalchemy import MetaData, create_engine-from backend.data.auth.oauth import cleanup_expired_oauth_tokensfrom backend.data.block import BlockInputfrom backend.data.execution import GraphExecutionWithNodesfrom backend.data.model import CredentialsMetaInput-from backend.data.onboarding import increment_onboarding_runsfrom backend.executor import utils as execution_utilsfrom backend.monitoring import (NotificationJobArgs,@@ -38,7 +36,11 @@ from backend.monitoring import (report_execution_accuracy_alerts,report_late_executions,)-from backend.util.clients import get_database_manager_client, get_scheduler_client+from backend.util.clients import (+ get_database_manager_async_client,+ get_database_manager_client,+ get_scheduler_client,+)from backend.util.cloud_storage import cleanup_expired_files_asyncfrom backend.util.exceptions import (GraphNotFoundError,@@ -148,6 +150,7 @@ def execute_graph(**kwargs):async def _execute_graph(**kwargs):args = GraphExecutionJobArgs(**kwargs)start_time = asyncio.get_event_loop().time()+ db = get_database_manager_async_client()try:logger.info(f"Executing recurring job for graph #{args.graph_id}")graph_exec: GraphExecutionWithNodes = await execution_utils.add_graph_execution(@@ -157,7 +160,7 @@ async def _execute_graph(**kwargs):inputs=args.input_data,graph_credentials_inputs=args.input_credentials,)- await increment_onboarding_runs(args.user_id)+ await db.increment_onboarding_runs(args.user_id)elapsed = asyncio.get_event_loop().time() - start_timelogger.info(f"Graph execution started with ID {graph_exec.id} for graph {args.graph_id} "@@ -246,8 +249,13 @@ def cleanup_expired_files():def cleanup_oauth_tokens():"""Clean up expired OAuth tokens from the database."""+# Wait for completion- run_async(cleanup_expired_oauth_tokens())+ async def _cleanup():+ db = get_database_manager_async_client()+ return await db.cleanup_expired_oauth_tokens()++ run_async(_cleanup())def execution_accuracy_alerts():