Skip to content

feat: add supervised background workers#138

Open
ItayTheDar wants to merge 1 commit into
mainfrom
agent/background-workers
Open

feat: add supervised background workers#138
ItayTheDar wants to merge 1 commit into
mainfrom
agent/background-workers

Conversation

@ItayTheDar

Copy link
Copy Markdown
Contributor

Summary

  • add dependency-injected BackgroundWorker and fixed-delay IntervalWorker APIs
  • add WorkerHost supervision with restart policies, capped exponential backoff, status reporting, cooperative shutdown, and forced cancellation after a grace timeout
  • start workers on the FastAPI lifespan loop and stop them before provider shutdown hooks
  • add standalone WorkerAppFactory and run_workers() support with SIGTERM/SIGINT handling
  • document worker deployment semantics and replace the unsafe lifespan-task recipe

Why

Creating long-lived asyncio tasks during the existing synchronous factory bootstrap can bind them to a temporary event loop that is closed immediately afterward. This feature gives background work a first-class runtime that creates tasks on the serving loop, while preserving normal PyNest dependency injection and lifecycle ordering.

Developer impact

Workers are registered as normal module providers and can use constructor injection. HTTP applications require no extra startup code, while dedicated worker processes can run without FastAPI. Recurring jobs can use IntervalWorker; cron/calendar semantics remain intentionally outside core because they require explicit timezone, persistence, misfire, and distributed-locking policies.

Validation

  • uv run pytest -q — 201 passed
  • Black check on all changed Python files — passed
  • uv run --group docs mkdocs build --strict — passed
  • git diff --check — passed

@ItayTheDar
ItayTheDar marked this pull request as ready for review July 25, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant