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
## Summary
Adds automatic result persistence for task executions using
`py-key-value-aio` storage, plus critical bug fixes for resource cleanup
and improved test coverage.
## ✨ New Feature: Result Persistence
Tasks can now store return values and exceptions for later retrieval:
```python
async def calculate() -> int:
return 42
execution = await docket.add(calculate)()
await worker.run_until_finished()
# Retrieve result (waits if task still running)
result = await execution.get_result() # Returns 42
```
### Key Features
- **Automatic serialization**: Uses cloudpickle for any Python object
- **Exception storage**: Failed tasks store exceptions, which are
re-raised on `get_result()`
- **Smart skipping**: Tasks returning `None` skip persistence
- **TTL management**: Results expire with `execution_ttl` (default: 1
hour)
- **Timeout support**: `get_result(timeout=...)` with graceful timeout
handling
- **Pub/sub integration**: Waits for completion via existing state
subscription
### Implementation Details
- `Docket.result_storage`: `RedisStore` or `MemoryStore` backend
- `Execution.result_key`: Tracks where result is stored
- `Execution.get_result()`: Retrieves results, waiting via pub/sub if
needed
- Worker captures return values/exceptions after task execution
- Base64-encoded JSON for storage compatibility
### Storage Backend
Uses `py-key-value-aio` with pluggable storage:
- **Redis**: `RedisStore` for production (separate connection pool)
- **Memory**: `MemoryStore` for `memory://` URLs (testing)
## 📚 API Changes
### New Public Methods
```python
execution.get_result(timeout=...) # New method
```
### Docket Configuration
```python
Docket(
result_storage=custom_storage # Optional: provide custom AsyncKeyValue
)
```
Closes#166
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <[email protected]>
0 commit comments