You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add FailureHandler and CompletionHandler base classes for dependency hooks (#299)
## Summary
Introduces two new abstract base classes that let dependencies control
post-execution flow:
- `FailureHandler` - controls what happens when a task fails. `Retry`
now inherits from this and implements `handle_failure()` to schedule
retries.
- `CompletionHandler` - controls what happens after task completion.
`Perpetual` now inherits from this and implements `on_complete()` to
schedule the next execution.
This follows the pattern established by `Runtime` for `Timeout`: the
Worker delegates control to specialized dependencies rather than knowing
the details itself. The Worker's `_retry_if_requested()` and
`_perpetuate_if_requested()` methods are removed (~50 lines), with that
logic now living in the dependencies.
The dependency hierarchy now looks like:
```
Dependency (base - can observe via __aexit__)
├── Runtime (controls HOW task executes - Timeout)
├── FailureHandler (controls WHAT HAPPENS on failure - Retry)
└── CompletionHandler (controls WHAT HAPPENS after completion - Perpetual)
```
All three have `single = True` because only one thing can control each
aspect.
Also adds `after(timedelta)` and `at(datetime)` methods to both
`Perpetual` and `Retry`, giving developers flexibility to schedule the
next execution using whatever they have handy. For `Retry`, the old
`in_()` method is kept as a backwards-compatible alias.
Closes#297
🤖 Generated with [Claude Code](https://claude.ai/code)
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
0 commit comments