This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Docket (pydocket on PyPI) is a distributed background task system for Python functions with Redis-backed persistence. It enables scheduling both immediate and future work with comprehensive dependency injection, retry mechanisms, and fault tolerance.
Key Requirements: Python 3.12+, Redis 6.2+ or Valkey 8.0+
# Run full test suite with coverage and parallel execution
pytest
# Run specific test
pytest tests/test_docket.py::test_specific_function
The project REQUIRES 100% test coverage
# Lint and format code
ruff check
ruff format
# Type checking
pyright
pyright tests
# Run all pre-commit hooks
pre-commit run --all-files# Install development dependencies
uv sync --group dev
# Install pre-commit hooks
pre-commit install- This project uses Github for issue tracking
- This project can use git worktrees under .worktrees/
-
Docket(src/docket/docket.py): Central task registry and scheduleradd(): Schedule tasks for executionreplace(): Replace existing scheduled taskscancel(): Cancel pending tasksstrike()/restore(): Conditionally block/unblock taskssnapshot(): Get current state for observability
-
Worker(src/docket/worker.py): Task execution enginerun_forever()/run_until_finished(): Main execution loops- Handles concurrency, retries, and dependency injection
- Maintains heartbeat for liveness tracking
-
Execution(src/docket/execution.py): Task execution context with metadata
Rich dependency injection supporting:
- Context access:
CurrentDocket,CurrentWorker,CurrentExecution - Retry strategies:
Retry,ExponentialRetry - Special behaviors:
Perpetual(self-rescheduling),Timeout - Custom injection:
Depends() - Contextual logging:
TaskLogger
- Streams:
{docket}:stream(ready tasks),{docket}:strikes(commands) - Sorted Sets:
{docket}:queue(scheduled tasks),{docket}:workers(heartbeats) - Hashes:
{docket}:{key}(parked task data) - Sets:
{docket}:worker-tasks:{worker}(worker capabilities)
- Registration with
Docket.register()or@docket.task - Scheduling: immediate → Redis stream, future → Redis sorted set
- Worker processing: scheduler moves due tasks, workers consume via consumer groups
- Execution: dependency injection, retry logic, acknowledgment
src/docket/- Main package__init__.py- Public API exportsdocket.py- Core Docket classworker.py- Worker implementationexecution.py- Task execution contextdependencies.py- Dependency injection systemtasks.py- Built-in utility taskscli.py- Command-line interface
tests/- Comprehensive test suiteexamples/- Usage exampleschaos/- Chaos testing framework
# Run a worker
docket worker --url redis://localhost:6379/0 --tasks your.module --concurrency 4
# See all commands
docket --help