Skip to content

Commit

Permalink
fix(platform): Stop the start up & shutdown of LaunchDarkly on local …
Browse files Browse the repository at this point in the history
…envs (Significant-Gravitas#8897)

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:
  <!-- Put your test plan here: -->
  - [ ] ...

<details>
  <summary>Example test plan</summary>
  
  - [ ] 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
</details>

#### 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**)

<details>
  <summary>Examples of configuration changes</summary>

  - Changing ports
  - Adding new services that need to communicate with each other
  - Secrets or environment variable changes
  - New or infrastructure changes such as databases
</details>
  • Loading branch information
aarushik93 authored Dec 6, 2024
1 parent dcfad26 commit ea6c9a1
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions autogpt_platform/backend/backend/server/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,26 @@
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()


Expand Down

0 comments on commit ea6c9a1

Please sign in to comment.