From ea6c9a1152782e2e7d44cec762b32568a82e6316 Mon Sep 17 00:00:00 2001 From: Aarushi <50577581+aarushik93@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:41:48 +0000 Subject: [PATCH] fix(platform): Stop the start up & shutdown of LaunchDarkly on local envs (#8897) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We aren't using Launch Darkly locally and so it's not set up but it was still attempting to shut down LaunchDarkly when the app shutdown, causing errors on shutdown. This PR fixes that issue by entirely disabling LD on local machines. ### Changes 🏗️ Added a contextmanager to handle LaunchDarkly start up and shutdown Added a check for local environment in said context manager ### Checklist 📋 #### For code changes: - [ ] I have clearly listed my changes in the PR description - [ ] I have made a test plan - [ ] I have tested my changes according to the test plan: - [ ] ...
Example test plan - [ ] Create from scratch and execute an agent with at least 3 blocks - [ ] Import an agent from file upload, and confirm it executes correctly - [ ] Upload agent to marketplace - [ ] Import an agent from marketplace and confirm it executes correctly - [ ] Edit an agent from monitor, and confirm it executes correctly
#### For configuration changes: - [ ] `.env.example` is updated or already compatible with my changes - [ ] `docker-compose.yml` is updated or already compatible with my changes - [ ] I have included a list of my configuration changes in the PR description (under **Changes**)
Examples of configuration changes - Changing ports - Adding new services that need to communicate with each other - Secrets or environment variable changes - New or infrastructure changes such as databases
--- .../backend/backend/server/rest_api.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/autogpt_platform/backend/backend/server/rest_api.py b/autogpt_platform/backend/backend/server/rest_api.py index d0ba73f65..0efe68862 100644 --- a/autogpt_platform/backend/backend/server/rest_api.py +++ b/autogpt_platform/backend/backend/server/rest_api.py @@ -25,15 +25,26 @@ logger = logging.getLogger(__name__) logging.getLogger("autogpt_libs").setLevel(logging.INFO) +@contextlib.contextmanager +def launch_darkly_context(): + if settings.config.app_env != backend.util.settings.AppEnvironment.LOCAL: + initialize_launchdarkly() + try: + yield + finally: + shutdown_launchdarkly() + else: + yield + + @contextlib.asynccontextmanager async def lifespan_context(app: fastapi.FastAPI): await backend.data.db.connect() await backend.data.block.initialize_blocks() await backend.data.user.migrate_and_encrypt_user_integrations() await backend.data.graph.fix_llm_provider_credentials() - initialize_launchdarkly() - yield - shutdown_launchdarkly() + with launch_darkly_context(): + yield await backend.data.db.disconnect()