Skip to content

Commit

Permalink
add comments, replace using reflect to check for empty Apply.Onwaitin…
Browse files Browse the repository at this point in the history
…gActions
  • Loading branch information
tlin4194 committed Nov 7, 2024
1 parent cbf4fa5 commit 4cc6c9f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions server/neptune/workflows/internal/deploy/terraform/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package terraform

import (
"fmt"
"reflect"

"github.com/pkg/errors"
"github.com/runatlantis/atlantis/server/metrics"
Expand Down Expand Up @@ -32,6 +31,8 @@ type StateReceiver struct {
}

func (n *StateReceiver) Receive(ctx workflow.Context, c workflow.ReceiveChannel, deploymentInfo DeploymentInfo) {
// deploymentInfo is the current deployment being processed in TerraformWorkflow. Receive is triggered whenever the TerraformWorkflow has a state change.

var workflowState *state.Workflow
c.Receive(ctx, &workflowState)

Expand All @@ -48,18 +49,18 @@ func (n *StateReceiver) Receive(ctx workflow.Context, c workflow.ReceiveChannel,
}
}

// 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.
if workflowState.Apply != nil &&
workflowState.Apply.Status == state.WaitingJobStatus &&
!reflect.ValueOf(workflowState.Apply.OnWaitingActions).IsZero() {
// update queue with information about current deployment pending confirm/reject action
infos := n.Queue.GetOrderedMergedItems()
len(workflowState.Apply.OnWaitingActions.Actions) > 0 {
queued_deployments := 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 infos {
for _, i := range queued_deployments {
request := notifier.GithubCheckRunRequest{
Title: notifier.BuildDeployCheckRunTitle(i.Root.Name),
Sha: i.Commit.Revision,
Expand All @@ -77,6 +78,7 @@ 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)
Expand Down

0 comments on commit 4cc6c9f

Please sign in to comment.