Преглед изворни кода

update predeploy activity feed event on error (#3767)

Feroze Mohideen пре 2 година
родитељ
комит
e4ae73b084
1 измењених фајлова са 9 додато и 2 уклоњено
  1. 9 2
      cli/cmd/v2/apply.go

+ 9 - 2
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)