-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathhook.go
48 lines (39 loc) · 1.55 KB
/
hook.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
//go:generate stringer -type=EventType
package hook
import "github.com/allegro/mesos-executor/mesosutils"
// EventType represents task lifecycle event type.
type EventType int
const (
// BeforeTaskStartEvent is an event type that occurs right before task is
// started. It is not guaranteed to occur in task lifecycle.
BeforeTaskStartEvent EventType = iota
// AfterTaskHealthyEvent is an event type that occurs right after first successful
// task health check pass.
AfterTaskHealthyEvent
// BeforeTerminateEvent is an event type that occurs right before task is terminated.
// It is guaranteed to occur in task lifecycle and to be last event received.
BeforeTerminateEvent
)
// NoopHook is a hook that ignores all events
type NoopHook struct {
}
// HandleEvent ignores all events
func (noop NoopHook) HandleEvent(event Event) (Env, error) {
return nil, nil
}
// Event is a container type for various event specific data.
type Event struct {
Type EventType
TaskInfo mesosutils.TaskInfo
}
// Env is a container for os.Environ style list of combined environment variable strings.
type Env []string
// Hook is an interface for various executor extensions, that can add some actions
// during task lifecycle events.
type Hook interface {
// HandleEvent is called when any of defined executor task events occurs.
// Received events may be handled in any way, but hook should ignore unknown or
// unsupported ones. Call to this function will block executor process until
// it returns. Order of received event types is undefined.
HandleEvent(Event) (Env, error)
}