Skip to content

Commit

Permalink
check-root-map
Browse files Browse the repository at this point in the history
  • Loading branch information
Samra Belachew committed Jul 25, 2023
1 parent 268ec39 commit 4d016ac
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
15 changes: 14 additions & 1 deletion server/neptune/workflows/internal/pr/revision/state.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package revision

import (
"fmt"
"github.com/pkg/errors"
"github.com/runatlantis/atlantis/server/metrics"
"github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier"
Expand All @@ -9,6 +10,10 @@ import (
"go.temporal.io/sdk/workflow"
)

const (
CheckBeforeNotify = "checkbeforenotify"
)

type WorkflowNotifier interface {
Notify(workflow.Context, notifier.Info, *state.Workflow) error
}
Expand All @@ -30,7 +35,15 @@ func (s *StateReceiver) Receive(ctx workflow.Context, c workflow.ReceiveChannel,
}

func (s *StateReceiver) Notify(ctx workflow.Context, workflowState *state.Workflow, roots map[string]RootInfo) {
rootInfo := roots[workflowState.ID]
rootInfo, ok := roots[workflowState.ID]

// TODO remove versioning
v := workflow.GetVersion(ctx, CheckBeforeNotify, workflow.DefaultVersion, workflow.Version(1))
if v != workflow.DefaultVersion && !ok {
workflow.GetLogger(ctx).Warn(fmt.Sprintf("skipping notifying root %s", workflowState.ID))
return
}

for _, notifier := range s.InternalNotifiers {
if err := notifier.Notify(ctx, rootInfo.ToInternalInfo(), workflowState); err != nil {
workflow.GetMetricsHandler(ctx).Counter("notifier_failure").Inc(1)
Expand Down
26 changes: 25 additions & 1 deletion server/neptune/workflows/internal/pr/revision/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestStateReceive(t *testing.T) {
},
}

t.Run("calls notifiers with state", func(t *testing.T) {
t.Run("calls notifiers with missing root info", func(t *testing.T) {
ts := testsuite.WorkflowTestSuite{}
env := ts.NewTestWorkflowEnvironment()

Expand All @@ -98,6 +98,30 @@ func TestStateReceive(t *testing.T) {
Output: jobOutput,
Status: state.WaitingJobStatus,
},
ID: internalRootInfo.ID.String(),
},
T: t,
})

env.AssertExpectations(t)

var result stateReceiveResponse
err = env.GetWorkflowResult(&result)
assert.False(t, result.NotifierCalled)
assert.NoError(t, err)
})

t.Run("calls notifiers with valid state", func(t *testing.T) {
ts := testsuite.WorkflowTestSuite{}
env := ts.NewTestWorkflowEnvironment()

env.ExecuteWorkflow(testStateReceiveWorkflow, stateReceiveRequest{
State: &state.Workflow{
Plan: &state.Job{
Output: jobOutput,
Status: state.WaitingJobStatus,
},
ID: internalRootInfo.ID.String(),
},
RootInfo: internalRootInfo,
T: t,
Expand Down

0 comments on commit 4d016ac

Please sign in to comment.