Repository navigation
Plugin session lifecycle features, fixes #104 - #106
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #106 +/- ##
======================================
Coverage ? 85.82%
======================================
Files ? 70
Lines ? 4495
Branches ? 0
======================================
Hits ? 3858
Misses ? 637
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Managed-task failures can leave startup blocked indefinitely, while interrupted rollback and ineffective metrics unsubscription can leave resources and subscriptions unreleased.
3 open issues
What changed in this PR
This PR introduces worker-owned plugin sessions and leadership leases to address transient PostgreSQL failures reported in #104. It centralizes retries, resource cleanup, and background-task supervision.
Changes:
- Adds session-based plugin operations and retryable transactions, migrating built-in plugins.
- Moves leadership into Worker, with lease validation, expiry, and transaction protection.
- Expands lifecycle regression tests and migration documentation; updates the macOS release runner.
| File | Description |
|---|---|
| tests/test_worker_supervision.py | Tests failure reporting, shutdown, and startup cancellation. |
| tests/test_task_manager.py | Tests cancellation ownership and retained failures. |
| tests/test_plugin_sessions.py | Tests sessions, transaction retries, and leadership protection. |
| tests/test_leadership.py | Adds core leadership and lease regression tests. |
| tests/test_cli.py | Tests dashboard session cleanup and failures. |
| tests/plugins/test_workflow.py | Migrates workflow tests to core leadership. |
| tests/plugins/test_workflow_scheduler.py | Uses sessions and tests polling deadlines. |
| tests/plugins/test_reprioritization.py | Removes the test leadership plugin. |
| tests/plugins/test_pruner.py | Removes the test leadership plugin. |
| tests/plugins/test_metrics.py | Tests transaction retries and updates cleanup calls. |
| tests/plugins/test_leadership.py | Removes obsolete plugin leadership tests. |
| tests/plugins/test_api.py | Adapts server tests to session setup. |
| examples/demo.py | Moves leadership configuration to Worker. |
| docs/howto/fastapi.rst | Explains embedded worker failure handling. |
| docs/design.rst | Documents core leadership ownership. |
| docs/conf.py | Adds annotation cross-reference exclusions. |
| docs/chancy.session.rst | Documents sessions, leadership, and shutdown migration. |
| docs/chancy.rst | Adds the session documentation entry. |
| docs/chancy.plugins.rst | Removes the leadership plugin entry. |
| docs/chancy.plugins.leadership.rst | Removes obsolete leadership plugin documentation. |
| CHANGELOG.md | Summarizes breaking APIs and lifecycle changes. |
| chancy/worker.py | Integrates sessions, leadership, and supervised teardown. |
| chancy/utils.py | Adds retained failures and handle-based task cancellation. |
| chancy/session.py | Implements plugin operations and resource ownership. |
| chancy/retry.py | Adds explicit retryable transaction conflicts. |
| chancy/plugins/workflow/__init__.py | Migrates scheduling and cleanup to sessions. |
| chancy/plugins/reprioritize.py | Adds retry-safe priority updates. |
| chancy/plugins/recovery.py | Uses protected, retryable recovery operations. |
| chancy/plugins/pruner.py | Registers pruning and plugin cleanup operations. |
| chancy/plugins/metrics/metrics.py | Migrates collection, flushing, and subscriptions. |
| chancy/plugins/leadership.py | Removes plugin-owned leadership implementations. |
| chancy/plugins/debug.py | Uses session-owned event subscriptions. |
| chancy/plugins/cron/__init__.py | Uses periodic operations and transaction retries. |
| chancy/plugins/api/core.py | Reports unhealthy workers with HTTP 503. |
| chancy/plugins/api/__init__.py | Registers the server as a session service. |
| chancy/plugins/__init__.py | Removes the leadership plugin description. |
| chancy/plugin.py | Defines session setup and transactional cleanup hooks. |
| chancy/leadership.py | Implements worker-owned leases and transaction guards. |
| chancy/hub.py | Adds optional handler-error isolation. |
| chancy/errors.py | Defines the leadership-loss exception. |
| chancy/cli/worker.py | Runs dashboard infrastructure through sessions. |
| chancy/app.py | Updates defaults and excludes expired leadership leases. |
| .github/workflows/release.yml | Switches the macOS runner to macos-26. |
Review effort: Balanced
| def _on_task_failure(self) -> None: | ||
| self._failure_event.set() | ||
| if not self._starting and self._stop_task is None: | ||
| self._begin_stop(self.shutdown_timeout) |
| self._workers[worker] = uuid4(), handler | ||
| session.callback(self._workers.pop, worker, None) | ||
| for kind in ("counter", "gauge", "histogram"): | ||
| session.subscribe(f"metrics.{kind}", handler) |
| await self.manager.cancel_all(timeout=self.teardown_timeout) | ||
| await self._close_sessions() | ||
| except BaseException as cleanup_error: |


No description provided.