Skip to content

Commit 221086d

Browse files
authored
Merge pull request #328 from thand-io/fix/deterministic-notifier-order
fix(workflows): deterministic notifier task ordering
2 parents 531a36e + 2641e19 commit 221086d

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

internal/workflows/tasks/providers/thand/approvals.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package thand
33
import (
44
"errors"
55
"fmt"
6+
"maps"
7+
"slices"
68
"time"
79

810
cloudevents "github.com/cloudevents/sdk-go/v2"
@@ -434,7 +436,8 @@ func (t *thandTask) makeApprovalNotifications(
434436
// In parallel create a notifier for each of the notifiers
435437
// Build notification tasks for each provider
436438
var notifyTasks []notifyTask
437-
for providerKey, notifierRequest := range approvalsTask.Notifiers {
439+
for _, providerKey := range slices.Sorted(maps.Keys(approvalsTask.Notifiers)) {
440+
notifierRequest := approvalsTask.Notifiers[providerKey]
438441
// Create an ApprovalNotifier for each provider
439442
approvalNotifier := NewApprovalsNotifier(
440443
t.config,
@@ -546,7 +549,8 @@ func (t *thandTask) notifyApprovalRejection(
546549
}
547550

548551
// Send rejection notification using each configured notifier
549-
for providerKey, notifierRequest := range approvalsTask.Notifiers {
552+
for _, providerKey := range slices.Sorted(maps.Keys(approvalsTask.Notifiers)) {
553+
notifierRequest := approvalsTask.Notifiers[providerKey]
550554
// Create a generic notifier for rejection with the approver as recipient
551555
rejectionRequest := thandFunction.NotifierRequest{
552556
Provider: notifierRequest.Provider,

internal/workflows/tasks/providers/thand/authorize.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package thand
33
import (
44
"errors"
55
"fmt"
6+
"maps"
67
"net/http"
8+
"slices"
79
"sync"
810
"time"
911

@@ -562,7 +564,8 @@ func (t *thandTask) makeAuthorizationNotifications(
562564

563565
// Build notification tasks for each provider
564566
var notifyTasks []notifyTask
565-
for providerKey, notifierRequest := range authorizeTask.Notifiers {
567+
for _, providerKey := range slices.Sorted(maps.Keys(authorizeTask.Notifiers)) {
568+
notifierRequest := authorizeTask.Notifiers[providerKey]
566569
// Create an AuthorizerNotifier for each provider
567570
authorizeNotifier := NewAuthorizerNotifier(
568571
t.config,

internal/workflows/tasks/providers/thand/form.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7+
"maps"
8+
"slices"
79

810
cloudevents "github.com/cloudevents/sdk-go/v2"
911
"github.com/serverlessworkflow/sdk-go/v3/model"
@@ -248,7 +250,8 @@ func (t *thandTask) makeFormNotifications(
248250

249251
var notifyTasks []notifyTask
250252

251-
for providerKey, notifierRequest := range formTask.Notifiers {
253+
for _, providerKey := range slices.Sorted(maps.Keys(formTask.Notifiers)) {
254+
notifierRequest := formTask.Notifiers[providerKey]
252255
// Create a FormNotifier for each provider
253256
formNotifier := NewFormNotifier(
254257
t.config,

internal/workflows/tasks/providers/thand/revoke.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package thand
33
import (
44
"errors"
55
"fmt"
6+
"maps"
7+
"slices"
68
"sync"
79
"time"
810

@@ -366,7 +368,8 @@ func (t *thandTask) makeRevocationNotifications(
366368

367369
// Build notification tasks for each provider
368370
var notifyTasks []notifyTask
369-
for providerKey, notifierRequest := range revokeTask.Notifiers {
371+
for _, providerKey := range slices.Sorted(maps.Keys(revokeTask.Notifiers)) {
372+
notifierRequest := revokeTask.Notifiers[providerKey]
370373
// Create a RevokeNotifier for each provider
371374
revokeNotifier := NewRevokeNotifier(
372375
t.config,

0 commit comments

Comments
 (0)