-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.go
75 lines (67 loc) · 2.42 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package sagas
var callableEventList = []Event{Running, Completed, Failed, Successed}
// Event is an interface that represents a state or status Event.
// It is used to define the type of the Event in the notification struct and
// can be a State or Status.
type Event interface {
// String returns the string representation of the event.
String() string
}
// Status is the status of a Step. It can be one of the following:
// Undefined, Canceled, Failed, Successed, Retry.
type Status int
const (
// Undefined indicates that Step status should treat this value as an undefined result. This is the default value
// and indicates that the Step action has not yet initiated.
Undefined Status = iota
// Failed indicates that Step status should treat this value as a failure. This is the value that will be
// returned if the Step action fails even after all retries.
Failed
// Successed indicates the Step status should treat this value as a success. This is the value that will be
// returned if the Step action succeeds before the maximum number of retries is reached.
Successed
// retry indicates the retrier should treat this value as a soft failure and retry. This is a internal value
// and should not be used by the user.
retry
)
// String returns the string representation of the status.
func (s Status) String() string {
switch s {
case Undefined:
return "Undefined"
case Failed:
return "Failed"
case Successed:
return "Successed"
case retry:
return "Retry"
default:
return "invalid status"
}
}
// State is the state of a step. It can be one of the following:
// Idle, Running, Completed.
type State int
const (
// Idle indicates that step state should treat this value as a static state. This is the default value
// and indicates that the Step action has not yet initiated.
Idle State = iota
// Running indicates that step state should treat this value as a state that is being executed. This is the value
// that will be returned if the Step action is running or retrying at the moment.
Running
// Completed indicates that step state should treat this value as a state that has been executed. This is the value
// that will be returned if the Step action has been executed.
Completed
)
// String returns the string representation of the state.
func (s State) String() string {
switch s {
case Idle:
return "Idle"
case Running:
return "Running"
case Completed:
return "Completed"
}
return "invalid state"
}