From e4ae73b084c36d1dad352e6f932eec79733ee229 Mon Sep 17 00:00:00 2001 From: Feroze Mohideen Date: Mon, 9 Oct 2023 11:51:29 -0400 Subject: [PATCH] update predeploy activity feed event on error (#3767) --- cli/cmd/v2/apply.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cli/cmd/v2/apply.go b/cli/cmd/v2/apply.go index 9f8d8c34ab..4d15fa4dbe 100644 --- a/cli/cmd/v2/apply.go +++ b/cli/cmd/v2/apply.go @@ -251,15 +251,23 @@ func Apply(ctx context.Context, inp ApplyInput) error { now := time.Now().UTC() eventID, _ := createPredeployEvent(ctx, client, appName, cliConf.Project, cliConf.Cluster, deploymentTargetID, now, applyResp.AppRevisionId) - + metadata := make(map[string]interface{}) eventStatus := types.PorterAppEventStatus_Success for { if time.Since(now) > checkPredeployTimeout { + eventStatus = types.PorterAppEventStatus_Failed + metadata["end_time"] = time.Now().UTC() + _ = updateExistingEvent(ctx, client, appName, cliConf.Project, cliConf.Cluster, deploymentTargetID, types.PorterAppEventType_PreDeploy, eventID, eventStatus, metadata) + return errors.New("timed out waiting for predeploy to complete") } predeployStatusResp, err := client.PredeployStatus(ctx, cliConf.Project, cliConf.Cluster, appName, applyResp.AppRevisionId) if err != nil { + eventStatus = types.PorterAppEventStatus_Failed + metadata["end_time"] = time.Now().UTC() + _ = updateExistingEvent(ctx, client, appName, cliConf.Project, cliConf.Cluster, deploymentTargetID, types.PorterAppEventType_PreDeploy, eventID, eventStatus, metadata) + return fmt.Errorf("error calling predeploy status endpoint: %w", err) } @@ -274,7 +282,6 @@ func Apply(ctx context.Context, inp ApplyInput) error { time.Sleep(checkPredeployFrequency) } - metadata := make(map[string]interface{}) metadata["end_time"] = time.Now().UTC() _ = updateExistingEvent(ctx, client, appName, cliConf.Project, cliConf.Cluster, deploymentTargetID, types.PorterAppEventType_PreDeploy, eventID, eventStatus, metadata)