-
-
Notifications
You must be signed in to change notification settings - Fork 523
/
supervision.go
46 lines (37 loc) · 1.37 KB
/
supervision.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
package actor
import "github.com/AsynkronIT/protoactor-go/eventstream"
// DeciderFunc is a function which is called by a SupervisorStrategy
type DeciderFunc func(reason interface{}) Directive
//SupervisorStrategy is an interface that decides how to handle failing child actors
type SupervisorStrategy interface {
HandleFailure(supervisor Supervisor, child *PID, rs *RestartStatistics, reason interface{}, message interface{})
}
//Supervisor is an interface that is used by the SupervisorStrategy to manage child actor lifecycle
type Supervisor interface {
Children() []*PID
EscalateFailure(reason interface{}, message interface{})
RestartChildren(pids ...*PID)
StopChildren(pids ...*PID)
ResumeChildren(pids ...*PID)
}
func logFailure(child *PID, reason interface{}, directive Directive) {
eventstream.Publish(&SupervisorEvent{
Child: child,
Reason: reason,
Directive: directive,
})
}
//DefaultDecider is a decider that will always restart the failing child actor
func DefaultDecider(_ interface{}) Directive {
return RestartDirective
}
var (
defaultSupervisionStrategy = NewOneForOneStrategy(10, 0, DefaultDecider)
restartingSupervisionStrategy = NewRestartingStrategy()
)
func DefaultSupervisorStrategy() SupervisorStrategy {
return defaultSupervisionStrategy
}
func RestartingSupervisorStrategy() SupervisorStrategy {
return restartingSupervisionStrategy
}