Skip to content

Phase 4.6: Background tasks → TaskRegistry#578

Merged
shikhalev merged 1 commit intomainfrom
server/phase-4.6-task-registry
Mar 16, 2026
Merged

Phase 4.6: Background tasks → TaskRegistry#578
shikhalev merged 1 commit intomainfrom
server/phase-4.6-task-registry

Conversation

@shikhalev
Copy link
Collaborator

Summary

  • Migrate 6 background tasks from raw asyncio.create_task() to TaskRegistry (Phase 0 infrastructure)
  • Extract task functions from orchestrator.py into domain modules
  • Add graceful task cancellation on shutdown via task_registry.cancel_all()

Changes

4 new files (task functions extracted from orchestrator):

File Tasks Type
modules/core/maintenance.py cleanup_expired_sessions (1h), periodic_vacuum (7d, initial_delay=24h) periodic
modules/knowledge/tasks.py build_wiki_embeddings, load_collection_indexes one-shot
modules/kanban/tasks.py sync_kanban_issues (15min, initial_delay=60s) periodic
modules/ecommerce/tasks.py woocommerce_daily_sync (daily 23:00 UTC) one-shot with internal cron

orchestrator.py (1121 → 1030 lines, −91):

  • Removed 6 inline task definitions + asyncio.create_task() calls
  • Added TaskRegistry instance + register() + start_all() in startup
  • Added cancel_all() in shutdown_event()
  • Removed unused asyncio, datetime, timedelta imports

Design decisions

  • WooCommerce sync registered as one-shot (manages its own cron-style sleep loop internally) since TaskRegistry doesn't support cron scheduling
  • Wiki RAG tasks use functools.partial(fn, wiki_rag) to pass the service instance, since TaskRegistry.register() expects a zero-arg callable
  • Core maintenance in modules/core/maintenance.py (not tasks.py) to avoid name collision with TaskRegistry infrastructure in modules/core/tasks.py
  • Lazy imports preserved in task functions to avoid circular import risk

Test plan

  • ruff check — clean
  • pytest tests/unit/ — 65 tests pass (including 8 TaskRegistry tests)
  • Docker deploy: verify tasks start correctly in logs

Closes #551

🤖 Generated with Claude Code

…Registry

- Extract session cleanup + vacuum to modules/core/maintenance.py
- Extract wiki embeddings + collection indexes to modules/knowledge/tasks.py
- Extract kanban GitHub sync to modules/kanban/tasks.py
- Extract WooCommerce daily sync to modules/ecommerce/tasks.py
- Replace 6 asyncio.create_task() calls with TaskRegistry.register() + start_all()
- Add task_registry.cancel_all() to shutdown_event for graceful cleanup
- orchestrator.py: 1121 → 1030 lines

Closes #551

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@shikhalev shikhalev merged commit 10c1a11 into main Mar 16, 2026
3 checks passed
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.

Phase 4.6: Background tasks → TaskRegistry

1 participant