Skip to content

Commit 1e2c0a8

Browse files
committed
workflow version patch for additional github checkrun updates due to Temporal nondeterministic workflow change
1 parent 4cc6c9f commit 1e2c0a8

File tree

1 file changed

+15
-10
lines changed
  • server/neptune/workflows/internal/deploy/terraform

1 file changed

+15
-10
lines changed

server/neptune/workflows/internal/deploy/terraform/state.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,32 @@ func (n *StateReceiver) Receive(ctx workflow.Context, c workflow.ReceiveChannel,
4848
workflow.GetLogger(ctx).Error(errors.Wrap(err, "notifying workflow state change").Error())
4949
}
5050
}
51+
// Updates github check run with Terraform statuses for the current running deployment
52+
for _, notifier := range n.InternalNotifiers {
53+
if err := notifier.Notify(ctx, deploymentInfo.ToInternalInfo(), workflowState); err != nil {
54+
workflow.GetMetricsHandler(ctx).Counter("notifier_failure").Inc(1)
55+
workflow.GetLogger(ctx).Error(errors.Wrap(err, "notifying workflow state change").Error())
56+
}
57+
}
5158

5259
// 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.
60+
// 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.
61+
// See https://docs.temporal.io/develop/go/versioning#patching for how to upgrade workflow version.
62+
v := workflow.GetVersion(ctx, "SurfaceQueueInCheckRuns", workflow.DefaultVersion, 1)
63+
if v == workflow.DefaultVersion {
64+
return
65+
}
5366
if workflowState.Apply != nil &&
5467
workflowState.Apply.Status == state.WaitingJobStatus &&
5568
len(workflowState.Apply.OnWaitingActions.Actions) > 0 {
56-
queued_deployments := n.Queue.GetOrderedMergedItems()
69+
queuedDeployments := n.Queue.GetOrderedMergedItems()
5770

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

63-
for _, i := range queued_deployments {
76+
for _, i := range queuedDeployments {
6477
request := notifier.GithubCheckRunRequest{
6578
Title: notifier.BuildDeployCheckRunTitle(i.Root.Name),
6679
Sha: i.Commit.Revision,
@@ -77,12 +90,4 @@ func (n *StateReceiver) Receive(ctx workflow.Context, c workflow.ReceiveChannel,
7790
}
7891
}
7992
}
80-
81-
// Updates github check run with Terraform statuses for the current running deployment
82-
for _, notifier := range n.InternalNotifiers {
83-
if err := notifier.Notify(ctx, deploymentInfo.ToInternalInfo(), workflowState); err != nil {
84-
workflow.GetMetricsHandler(ctx).Counter("notifier_failure").Inc(1)
85-
workflow.GetLogger(ctx).Error(errors.Wrap(err, "notifying workflow state change").Error())
86-
}
87-
}
8893
}

0 commit comments

Comments
 (0)