Skip to content

Commit

Permalink
use thread_cached_property
Browse files Browse the repository at this point in the history
  • Loading branch information
majdyz committed Oct 15, 2024
1 parent da7d35e commit b8c1a3b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions autogpt_platform/backend/backend/executor/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from backend.data.model import CREDENTIALS_FIELD_NAME, CredentialsMetaInput
from backend.integrations.creds_manager import IntegrationCredentialsManager
from backend.util import json
from backend.util.cache import thread_cached_property
from backend.util.decorator import error_logged, time_measured
from backend.util.logging import configure_logging
from backend.util.process import set_service_name
Expand Down Expand Up @@ -661,7 +662,6 @@ def run_service(self):
SupabaseIntegrationCredentialsStore,
)

self.thread_local = threading.local()
self.credentials_store = SupabaseIntegrationCredentialsStore(
self.supabase, redis.get_redis()
)
Expand Down Expand Up @@ -694,11 +694,9 @@ def cleanup(self):

super().cleanup()

@property
@thread_cached_property
def db_client(self) -> "DatabaseAPI":
if not hasattr(self.thread_local, "db_client"):
self.thread_local.db_client = get_db_client()
return self.thread_local.db_client
return get_db_client()

@expose
def add_execution(
Expand Down
2 changes: 1 addition & 1 deletion autogpt_platform/backend/backend/executor/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def log(msg, **kwargs):


class ExecutionScheduler(AppService):
use_db = True

def __init__(self, refresh_interval=10):
super().__init__(port=Config().execution_scheduler_port)
self.use_db = True
self.last_check = datetime.min
self.refresh_interval = refresh_interval

Expand Down

0 comments on commit b8c1a3b

Please sign in to comment.