Files
AutoGPT/autogpt_platform/backend/executor/cached_client.py
Zamil Majdy 0b7b4af622 feat(backend/executor): implement execution data client abstraction
- Created modular execution_data_client to abstract DB and caching
- Simple in-memory cache for hot path operations (get_node, get_node_executions)
- Non-blocking queue for output and status updates
- Removed direct references to DatabaseManager and Redis from manager.py
- All execution data access now goes through generic ExecutionDataClient

This reduces blocking I/O operations during graph execution by caching frequently accessed data in memory and queuing non-critical updates.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-26 23:50:57 +00:00

61 lines
2.0 KiB
Python

import logging
from typing import Any
from backend.executor.simple_cache import get_cache
logger = logging.getLogger(__name__)
class CachedDatabaseClient:
def __init__(self, original_client):
self._client = original_client
self._cache = get_cache()
def get_node(self, node_id: str) -> Any:
cached = self._cache.get_node(node_id)
if cached:
return cached
node = self._client.get_node(node_id)
if node:
self._cache.cache_node(node_id, node)
return node
def get_node_executions(self, graph_exec_id: str, *args, **kwargs) -> Any:
if not args and not kwargs:
cached = self._cache.get_node_executions(graph_exec_id)
if cached:
return cached
executions = self._client.get_node_executions(graph_exec_id, *args, **kwargs)
if not args and not kwargs:
self._cache.cache_node_executions(graph_exec_id, executions)
return executions
def upsert_execution_output(self, *args, **kwargs) -> Any:
node_exec_id = kwargs.get("node_exec_id") or (args[0] if args else None)
output = kwargs.get("output") or (args[1] if len(args) > 1 else None)
if node_exec_id and output:
self._cache.queue_output_update(node_exec_id, output)
return {"success": True}
return self._client.upsert_execution_output(*args, **kwargs)
def update_node_execution_status(self, *args, **kwargs) -> Any:
node_exec_id = kwargs.get("node_exec_id") or (args[0] if args else None)
status = kwargs.get("status") or (args[1] if len(args) > 1 else None)
if node_exec_id and status:
self._cache.queue_status_update(node_exec_id, status)
return {"success": True}
return self._client.update_node_execution_status(*args, **kwargs)
def __getattr__(self, name):
return getattr(self._client, name)
def wrap_client(original_client):
return CachedDatabaseClient(original_client)