feat(lifecycle): add billing lifecycle with auto-suspend/delete

- New AppLifecycleService with cron-based scanner (60s interval)
- State machine: ACTIVE → SUSPENDED → PENDING_DELETION → DELETED
- Auto-renew hourly plans from wallet
- Admin-configurable grace periods via PlatformSettings table
- New LifecycleController (GET/PATCH /lifecycle/settings)
- PlatformSetting entity for runtime admin config
- BillingService: calculateCostForApp, deductWallet
- Application entity: planId, billingCycle, lifecycleStatus, planExpiresAt
- New enums: AppLifecycleStatus, BillingCycle
This commit is contained in:
keyhan
2026-04-22 16:44:20 +03:30
parent 0e408d1baa
commit 8ca787d46e
11 changed files with 562 additions and 11 deletions
+23
View File
@@ -288,4 +288,27 @@ export class BillingService {
async getAllWallets(): Promise<Wallet[]> {
return this.walletRepo.find({ relations: ['user'], order: { balance: 'DESC' } });
}
/**
* Calculate cost for an existing Application entity.
* Used by lifecycle service for auto-renew.
*/
async calculateCostForApp(app: {
runtime: string;
databaseType: string;
cpuLimit: string;
memoryLimit: string;
replicas: number;
dbStorageSize?: string;
}): Promise<{ hourly: number; monthly: number; yearly: number }> {
const result = await this.calculateCost({
runtime: app.runtime,
databaseType: app.databaseType,
cpuLimit: app.cpuLimit,
memoryLimit: app.memoryLimit,
replicas: app.replicas,
dbStorageSize: app.dbStorageSize,
});
return { hourly: result.hourly, monthly: result.monthly, yearly: result.yearly };
}
}