Skip to content

Commit

Permalink
workflow version patch for additional github checkrun updates due to …
Browse files Browse the repository at this point in the history
…Temporal nondeterministic workflow change
  • Loading branch information
tlin4194 committed Nov 7, 2024
1 parent 4cc6c9f commit 1e2c0a8
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions server/neptune/workflows/internal/deploy/terraform/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,32 @@ func (n *StateReceiver) Receive(ctx workflow.Context, c workflow.ReceiveChannel,
workflow.GetLogger(ctx).Error(errors.Wrap(err, "notifying workflow state change").Error())
}
}
// Updates github check run with Terraform statuses for the current running deployment
for _, notifier := range n.InternalNotifiers {
if err := notifier.Notify(ctx, deploymentInfo.ToInternalInfo(), workflowState); err != nil {
workflow.GetMetricsHandler(ctx).Counter("notifier_failure").Inc(1)
workflow.GetLogger(ctx).Error(errors.Wrap(err, "notifying workflow state change").Error())
}
}

// Updates all other deployments waiting in queue when the current deployment is pending a confirm/reject user action. Current deployment is not on the queue at this point since its child TerraformWorkflow was started.
// CheckRunCache.CreateOrUpdate executes an activity and is a nondeterministic operation (i.e. it is not guaranteed to be executed in the same order across different workflow runs). This is why we need to check the workflow version to determine if we should update the check run.
// See https://docs.temporal.io/develop/go/versioning#patching for how to upgrade workflow version.
v := workflow.GetVersion(ctx, "SurfaceQueueInCheckRuns", workflow.DefaultVersion, 1)
if v == workflow.DefaultVersion {
return
}
if workflowState.Apply != nil &&
workflowState.Apply.Status == state.WaitingJobStatus &&
len(workflowState.Apply.OnWaitingActions.Actions) > 0 {
queued_deployments := n.Queue.GetOrderedMergedItems()
queuedDeployments := n.Queue.GetOrderedMergedItems()

revisionsSummary := n.Queue.GetQueuedRevisionsSummary()
state := github.CheckRunQueued
runLink := github.BuildRunURLMarkdown(deploymentInfo.Repo.GetFullName(), deploymentInfo.Commit.Revision, deploymentInfo.CheckRunID)
summary := fmt.Sprintf("This deploy is queued pending action on run for revision %s.\n%s", runLink, revisionsSummary)

for _, i := range queued_deployments {
for _, i := range queuedDeployments {
request := notifier.GithubCheckRunRequest{
Title: notifier.BuildDeployCheckRunTitle(i.Root.Name),
Sha: i.Commit.Revision,
Expand All @@ -77,12 +90,4 @@ func (n *StateReceiver) Receive(ctx workflow.Context, c workflow.ReceiveChannel,
}
}
}

// Updates github check run with Terraform statuses for the current running deployment
for _, notifier := range n.InternalNotifiers {
if err := notifier.Notify(ctx, deploymentInfo.ToInternalInfo(), workflowState); err != nil {
workflow.GetMetricsHandler(ctx).Counter("notifier_failure").Inc(1)
workflow.GetLogger(ctx).Error(errors.Wrap(err, "notifying workflow state change").Error())
}
}
}

0 comments on commit 1e2c0a8

Please sign in to comment.