From aaa55fd153d6fda793626e28e0687a0bbffa61dd Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 1 Jan 2026 06:59:03 -0800 Subject: [PATCH] Fix app status not updated when deployment fails or service restarts - Update app status to error when health check fails with an error - Update app status to error in cleanupStuckDeployments for apps stuck in building state - This fixes the inconsistency where app shows "building" but deployment is "failed" --- internal/service/deploy/deploy.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/internal/service/deploy/deploy.go b/internal/service/deploy/deploy.go index 0f355a8..1c3f191 100644 --- a/internal/service/deploy/deploy.go +++ b/internal/service/deploy/deploy.go @@ -386,7 +386,8 @@ func (svc *Service) deployContainerWithTimeout( // cleanupStuckDeployments marks any deployments stuck in building/deploying as failed. func (svc *Service) cleanupStuckDeployments(ctx context.Context) error { - query := ` + // First, update the deployments + deployQuery := ` UPDATE deployments SET status = ?, finished_at = ?, logs = COALESCE(logs, '') || ? WHERE status IN (?, ?) @@ -395,7 +396,7 @@ func (svc *Service) cleanupStuckDeployments(ctx context.Context) error { _, err := svc.db.DB().ExecContext( ctx, - query, + deployQuery, models.DeploymentStatusFailed, time.Now(), msg, @@ -408,7 +409,27 @@ func (svc *Service) cleanupStuckDeployments(ctx context.Context) error { return fmt.Errorf("failed to cleanup stuck deployments: %w", err) } - svc.log.Info("cleaned up stuck deployments") + // Also update app status for apps that were stuck in building + appQuery := ` + UPDATE apps + SET status = ?, updated_at = ? + WHERE status = ? + ` + + _, err = svc.db.DB().ExecContext( + ctx, + appQuery, + models.AppStatusError, + time.Now(), + models.AppStatusBuilding, + ) + if err != nil { + svc.log.Error("failed to cleanup stuck app statuses", "error", err) + + return fmt.Errorf("failed to cleanup stuck app statuses: %w", err) + } + + svc.log.Info("cleaned up stuck deployments and app statuses") return nil } @@ -893,6 +914,9 @@ func (svc *Service) checkHealthAfterDelay( svc.log.Error("failed to check container health", "error", err) svc.notify.NotifyDeployFailed(ctx, reloadedApp, deployment, err) _ = deployment.MarkFinished(ctx, models.DeploymentStatusFailed) + svc.writeLogsToFile(reloadedApp, deployment) + reloadedApp.Status = models.AppStatusError + _ = reloadedApp.Save(ctx) return }