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>
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
# app/tasks/celery_tasks/subscription.py
|
|
"""
|
|
Legacy subscription tasks.
|
|
|
|
MOSTLY MIGRATED: Most tasks have been migrated to app.modules.billing.tasks.
|
|
|
|
The following tasks now live in the billing module:
|
|
- reset_period_counters -> app.modules.billing.tasks.subscription
|
|
- check_trial_expirations -> app.modules.billing.tasks.subscription
|
|
- sync_stripe_status -> app.modules.billing.tasks.subscription
|
|
- cleanup_stale_subscriptions -> app.modules.billing.tasks.subscription
|
|
|
|
Remaining task (to be migrated to monitoring module):
|
|
- capture_capacity_snapshot
|
|
"""
|
|
|
|
import logging
|
|
|
|
from app.core.celery_config import celery_app
|
|
from app.tasks.celery_tasks.base import DatabaseTask
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@celery_app.task(
|
|
bind=True,
|
|
base=DatabaseTask,
|
|
name="app.tasks.celery_tasks.subscription.capture_capacity_snapshot",
|
|
)
|
|
def capture_capacity_snapshot(self):
|
|
"""
|
|
Capture a daily snapshot of platform capacity metrics.
|
|
|
|
Runs daily at midnight.
|
|
|
|
TODO: Migrate to app.modules.monitoring.tasks
|
|
"""
|
|
from app.services.capacity_forecast_service import capacity_forecast_service
|
|
|
|
with self.get_db() as db:
|
|
snapshot = capacity_forecast_service.capture_daily_snapshot(db)
|
|
db.commit()
|
|
|
|
logger.info(
|
|
f"Captured capacity snapshot: {snapshot.total_vendors} vendors, "
|
|
f"{snapshot.total_products} products"
|
|
)
|
|
|
|
return {
|
|
"snapshot_id": snapshot.id,
|
|
"snapshot_date": snapshot.snapshot_date.isoformat(),
|
|
"total_vendors": snapshot.total_vendors,
|
|
"total_products": snapshot.total_products,
|
|
}
|