feat: add Celery task infrastructure for module system
Phase 4 of module migration plan: - Add ScheduledTask dataclass for declaring Celery Beat tasks - Add tasks_path and scheduled_tasks fields to ModuleDefinition - Create ModuleTask base class with database session management - Create task discovery utilities (discover_module_tasks, build_beat_schedule) - Update celery_config.py to discover and register module tasks - Maintain backward compatibility with legacy task modules Modules can now define tasks in their tasks/ directory and scheduled tasks in their definition. The infrastructure supports gradual migration of existing tasks from app/tasks/ to their respective modules. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ Module Hierarchy:
|
||||
└── Modules (Enabled features - Billing, Marketplace, Inventory, etc.)
|
||||
├── Routes (API + Page routes)
|
||||
├── Services (Business logic)
|
||||
├── Tasks (Celery background jobs)
|
||||
├── Menu Items (Sidebar entries)
|
||||
├── Templates (UI components)
|
||||
└── Migrations (Module-specific)
|
||||
@@ -52,7 +53,14 @@ Usage:
|
||||
print(f"Module {data.module_code} enabled")
|
||||
"""
|
||||
|
||||
from app.modules.base import ModuleDefinition
|
||||
from app.modules.base import ModuleDefinition, ScheduledTask
|
||||
from app.modules.task_base import ModuleTask, DatabaseTask
|
||||
from app.modules.tasks import (
|
||||
discover_module_tasks,
|
||||
build_beat_schedule,
|
||||
parse_schedule,
|
||||
get_module_task_routes,
|
||||
)
|
||||
from app.modules.registry import (
|
||||
MODULES,
|
||||
CORE_MODULES,
|
||||
@@ -76,6 +84,14 @@ from app.modules.events import (
|
||||
__all__ = [
|
||||
# Core types
|
||||
"ModuleDefinition",
|
||||
"ScheduledTask",
|
||||
# Task support
|
||||
"ModuleTask",
|
||||
"DatabaseTask",
|
||||
"discover_module_tasks",
|
||||
"build_beat_schedule",
|
||||
"parse_schedule",
|
||||
"get_module_task_routes",
|
||||
# Module dictionaries
|
||||
"MODULES",
|
||||
"CORE_MODULES",
|
||||
|
||||
Reference in New Issue
Block a user