fix(deploy): persist replica snapshot before stop for restore on start

Read live deployment replica counts from K8s before scaling to zero,
store them on the application as suspendedReplicas, and use that snapshot
when resuming so Start restores the pre-stop replica layout.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
keyhan
2026-05-15 01:03:52 +03:30
parent 195b3f5bab
commit 7c7e8ae254
5 changed files with 73 additions and 8 deletions
@@ -74,6 +74,8 @@ export class AppLifecycleService implements OnModuleInit, OnModuleDestroy {
if (app.latestImageTag) {
try {
await this.kubernetesService.resumeApplication(app);
app.suspendedReplicas = undefined;
await this.appRepo.save(app);
this.logger.log(`Reactivated ${app.name} — resumed with ${app.replicas} replicas, expires ${expiresAt.toISOString()}`);
} catch (e: any) {
this.logger.warn(`Failed to resume ${app.name} on reactivation: ${e.message}`);
@@ -138,7 +140,11 @@ export class AppLifecycleService implements OnModuleInit, OnModuleDestroy {
// Suspend: scale app and database to 0
try {
await this.kubernetesService.suspendApplication(app);
const snapshot = await this.kubernetesService.suspendApplication(app);
app.suspendedReplicas = snapshot;
if (snapshot[app.name] !== undefined) {
app.replicas = snapshot[app.name];
}
} catch (e: any) {
this.logger.warn(`Failed to suspend ${app.name} in K8s: ${e.message}`);
}