Skip to content

Commit

Permalink
update predeploy activity feed event on error (#3767)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feroze Mohideen authored Oct 9, 2023
1 parent 2619eb3 commit e4ae73b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cli/cmd/v2/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)

Expand Down

0 comments on commit e4ae73b

Please sign in to comment.