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:
@@ -29,7 +29,7 @@ Transform the platform from a monolithic structure to self-contained modules whe
|
||||
|--------|---------------|---------------|----------|--------|-------|--------|
|
||||
| `cms` | Core | ✅ **Complete** | ✅ | ✅ | - | Done |
|
||||
| `payments` | Optional | 🟡 Partial | ✅ | ✅ | - | Done |
|
||||
| `billing` | Optional | 🔴 Shell | ❌ | ❌ | ❌ | Full |
|
||||
| `billing` | Optional | ✅ **Complete** | ✅ | ✅ | ✅ | Done |
|
||||
| `marketplace` | Optional | 🔴 Shell | ❌ | ❌ | ❌ | Full |
|
||||
| `orders` | Optional | 🔴 Shell | ❌ | ❌ | - | Full |
|
||||
| `inventory` | Optional | 🔴 Shell | ❌ | ❌ | - | Full |
|
||||
@@ -110,85 +110,22 @@ app/tasks/celery_tasks/ # → Move to respective modules
|
||||
- Observability docs
|
||||
- Creating modules developer guide
|
||||
|
||||
---
|
||||
### ✅ Phase 4: Celery Task Infrastructure
|
||||
- Added `ScheduledTask` dataclass to `ModuleDefinition`
|
||||
- Added `tasks_path` and `scheduled_tasks` fields
|
||||
- Created `app/modules/task_base.py` with `ModuleTask` base class
|
||||
- Created `app/modules/tasks.py` with discovery utilities
|
||||
- Updated `celery_config.py` to use module discovery
|
||||
|
||||
## Infrastructure Work (Remaining)
|
||||
|
||||
### Phase 4: Celery Task Infrastructure
|
||||
|
||||
Add task support to module system before migrating modules.
|
||||
|
||||
#### 4.1 Update ModuleDefinition
|
||||
|
||||
```python
|
||||
# app/modules/base.py - Add fields
|
||||
|
||||
@dataclass
|
||||
class ScheduledTask:
|
||||
"""Celery Beat scheduled task definition."""
|
||||
name: str # e.g., "billing.reset_counters"
|
||||
task: str # Full task path
|
||||
schedule: str | dict # Cron string or crontab dict
|
||||
args: tuple = ()
|
||||
kwargs: dict = field(default_factory=dict)
|
||||
|
||||
@dataclass
|
||||
class ModuleDefinition:
|
||||
# ... existing fields ...
|
||||
|
||||
# Task configuration (NEW)
|
||||
tasks_path: str | None = None
|
||||
scheduled_tasks: list[ScheduledTask] = field(default_factory=list)
|
||||
```
|
||||
|
||||
#### 4.2 Create Task Discovery
|
||||
|
||||
```python
|
||||
# app/modules/tasks.py (NEW)
|
||||
|
||||
def discover_module_tasks() -> list[str]:
|
||||
"""Discover task modules from all registered modules."""
|
||||
...
|
||||
|
||||
def build_beat_schedule() -> dict:
|
||||
"""Build Celery Beat schedule from module definitions."""
|
||||
...
|
||||
```
|
||||
|
||||
#### 4.3 Create Module Task Base
|
||||
|
||||
```python
|
||||
# app/modules/task_base.py (NEW)
|
||||
|
||||
class ModuleTask(Task):
|
||||
"""Base Celery task with DB session management."""
|
||||
|
||||
@contextmanager
|
||||
def get_db(self):
|
||||
...
|
||||
```
|
||||
|
||||
#### 4.4 Update Celery Config
|
||||
|
||||
```python
|
||||
# app/core/celery_config.py
|
||||
|
||||
from app.modules.tasks import discover_module_tasks, build_beat_schedule
|
||||
|
||||
# Auto-discover from modules
|
||||
celery_app.autodiscover_tasks(discover_module_tasks())
|
||||
|
||||
# Build schedule from modules
|
||||
celery_app.conf.beat_schedule = build_beat_schedule()
|
||||
```
|
||||
|
||||
**Files to create:**
|
||||
- `app/modules/tasks.py`
|
||||
- `app/modules/task_base.py`
|
||||
|
||||
**Files to modify:**
|
||||
- `app/modules/base.py`
|
||||
- `app/core/celery_config.py`
|
||||
### ✅ Phase 5: Billing Module Migration
|
||||
- Created `app/modules/billing/services/` with subscription, stripe, admin services
|
||||
- Created `app/modules/billing/models/` re-exporting from central location
|
||||
- Created `app/modules/billing/schemas/` re-exporting from central location
|
||||
- Created `app/modules/billing/tasks/` with 4 scheduled tasks
|
||||
- Created `app/modules/billing/exceptions.py`
|
||||
- Updated `definition.py` with self-contained configuration
|
||||
- Created backward-compatible re-exports in `app/services/`
|
||||
- Updated legacy celery_config.py to not duplicate scheduled tasks
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user