Add POST /playbooks/reload endpoint for hot-reload#121
Merged
Conversation
Closes #112. Playbooks previously required a full API restart to pick up source changes. This adds a PlaybookRegistry.clear_and_reload() helper that wipes the module cache + _PLAYBOOK_REGISTRY and re-imports all configured playbook directories, exposed via an admin-only POST endpoint that also syncs the refreshed registry back to the database. In-flight executions hold a reference to the pre-reload function object and complete with the old code; new invocations use the refreshed registry.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughAdded authenticated API endpoint Changes
Sequence DiagramsequenceDiagram
actor Client
participant API as /playbooks/reload
participant Registry as PlaybookRegistry
participant Modules as sys.modules
participant ImportLib as importlib
participant DB as Database
Client->>API: POST /playbooks/reload (authenticated)
API->>Registry: instantiate with settings.playbook_directories
Registry->>Modules: remove stale playbook module entries
Registry->>ImportLib: invalidate_caches()
Registry->>Registry: clear global _PLAYBOOK_REGISTRY
Registry->>Registry: discover() re-scan playbooks
Registry->>Modules: import refreshed modules
API->>DB: sync_to_db(session)
API->>Client: return {count, status}
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PlaybookRegistry.clear_and_reload()which wipes the playbook module cache +_PLAYBOOK_REGISTRYand re-runs discovery against the configured directories.POST /api/v1/playbooks/reloadendpoint guarded byPermission.PLAYBOOKS_MANAGEthat calls the helper, syncs the refreshed registry to the database, and returns the loaded playbook count.In-flight playbook executions keep a reference to the pre-reload function object and complete with the old code; subsequent invocations use the refreshed registry.
Closes #112.
Test plan
ruff check src/ tests/passesclear_and_reloadrefreshes registry metadata when a playbook file is mutated on diskclear_and_reloaddrops playbooks whose files were deletedpytest tests/— 551 passedSummary by CodeRabbit
New Features
Tests