Skip to content

Commit

Permalink
add failure_or_done notification stragegy
Browse files Browse the repository at this point in the history
Signed-off-by: Wesley GALIPO <wesley.galipo@ovhcloud.com>
  • Loading branch information
Galiley authored and rclsilver committed May 25, 2023
1 parent 9acb484 commit 5bbcff1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/notify/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ func validateStrategyForAction(action, strategy string) error {
if action == notify.TaskValidationKey {
return errNotAllowed
}
case utask.NotificationStrategyFailureOrDone:
if action == notify.TaskValidationKey {
return errNotAllowed
}
default:
return errUnknown
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/notify/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ func checkIfDeliverMessageFromTaskState(m *Message, strategy string) bool {
if v, ok := m.Fields["state"]; ok && v == stateBlocked {
send = true
}
case utask.NotificationStrategyFailureOrDone:
if v, ok := m.Fields["state"]; ok && (v == stateBlocked || v == step.StateDone) {
send = true
}
case utask.NotificationStrategySilent:
}

Expand All @@ -254,6 +258,13 @@ func checkIfDeliverMessageFromStepState(m *Message, strategy string) bool {
send = true
}
}
case utask.NotificationStrategyFailureOrDone:
if v, ok := m.Fields["step_state"]; ok {
switch v {
case step.StateFatalError, step.StateCrashed, step.StateAfterrunError, step.StateDone:
send = true
}
}
case utask.NotificationStrategySilent:
}

Expand Down
2 changes: 2 additions & 0 deletions utask.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ const (
NotificationStrategyAlways = "always"
// NotificationStrategyFailureOnly corresponds to the mode where notifications will only be sent if the state is BLOCKED
NotificationStrategyFailureOnly = "failure_only"
// NotificationStrategyFailureOrDone corresponds to the mode where notifications will only be sent if the state is BLOCKED or DONE
NotificationStrategyFailureOrDone = "failure_or_done"

// UsernamesSeparator corresponds to the separator used to break a string into a list of usernames and vice versa.
UsernamesSeparator = ","
Expand Down

0 comments on commit 5bbcff1

Please sign in to comment.