feat: complete billing module migration (Phase 5)

Migrates billing module to self-contained structure:
- Create app/modules/billing/services/ with subscription, stripe, admin services
- Create app/modules/billing/models/ re-exporting from central location
- Create app/modules/billing/schemas/ re-exporting from central location
- Create app/modules/billing/tasks/ with 4 scheduled Celery tasks
- Create app/modules/billing/exceptions.py with module-specific exceptions
- Update definition.py with is_self_contained=True and scheduled_tasks

Celery task migration:
- reset_period_counters -> billing module
- check_trial_expirations -> billing module
- sync_stripe_status -> billing module
- cleanup_stale_subscriptions -> billing module
- capture_capacity_snapshot remains in legacy (will go to monitoring)

Backward compatibility:
- Create re-exports in app/services/ for subscription, stripe, admin services
- Old import paths continue to work
- Update celery_config.py to use module-defined schedules

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-27 23:06:23 +01:00
parent f1f91abe51
commit 4f379b472b
17 changed files with 2198 additions and 1931 deletions

View File

@@ -3,10 +3,10 @@
Billing module definition.
Defines the billing module including its features, menu items,
and route configurations.
route configurations, and scheduled tasks.
"""
from app.modules.base import ModuleDefinition
from app.modules.base import ModuleDefinition, ScheduledTask
from models.database.admin_menu_config import FrontendType
@@ -54,6 +54,44 @@ billing_module = ModuleDefinition(
],
},
is_core=False, # Billing can be disabled (e.g., internal platforms)
# =========================================================================
# Self-Contained Module Configuration
# =========================================================================
is_self_contained=True,
services_path="app.modules.billing.services",
models_path="app.modules.billing.models",
schemas_path="app.modules.billing.schemas",
exceptions_path="app.modules.billing.exceptions",
tasks_path="app.modules.billing.tasks",
# =========================================================================
# Scheduled Tasks
# =========================================================================
scheduled_tasks=[
ScheduledTask(
name="billing.reset_period_counters",
task="app.modules.billing.tasks.subscription.reset_period_counters",
schedule="5 0 * * *", # Daily at 00:05
options={"queue": "scheduled"},
),
ScheduledTask(
name="billing.check_trial_expirations",
task="app.modules.billing.tasks.subscription.check_trial_expirations",
schedule="0 1 * * *", # Daily at 01:00
options={"queue": "scheduled"},
),
ScheduledTask(
name="billing.sync_stripe_status",
task="app.modules.billing.tasks.subscription.sync_stripe_status",
schedule="30 * * * *", # Hourly at :30
options={"queue": "scheduled"},
),
ScheduledTask(
name="billing.cleanup_stale_subscriptions",
task="app.modules.billing.tasks.subscription.cleanup_stale_subscriptions",
schedule="0 3 * * 0", # Weekly on Sunday at 03:00
options={"queue": "scheduled"},
),
],
)