-
Notifications
You must be signed in to change notification settings - Fork 5
/
life_cycle.go
79 lines (64 loc) · 1.73 KB
/
life_cycle.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
76
77
78
79
package conveyor
import (
"database/sql/driver"
"sync"
)
// Valid States for a Conveyor
const (
// StatusPreparing status is used to mark a conveyor to be in "preparing" state
StatusPreparing = "preparing"
// StateStarted status is used to mark a conveyor to be in "started" state
StateStarted = "started"
// StateToKill status is used to mark a conveyor has been setup "to be killed", but isn't yet dead
StateToKill = "toKill"
// StateKilled status is used to mark a conveyor as "successfully killed"
StateKilled = "killed"
// StateFinished status is used to mark a conveyor as "successfully finished"
StateFinished = "finished"
// StateInternalError status is used to indicate that conveyor couldn't finish due to some internal error
StateInternalError = "internalError"
)
var (
driversMu sync.RWMutex
drivers = make(map[string]driver.Driver)
)
type ProgressUpdater interface {
GetState() (string, error)
GetStatusMsg() (string, error)
UpdateStatusMsg(string) error
GetProgress() (string, error)
UpdateProgress(string) error
}
type StateUpdater interface {
MarkPreparing() error
MarkStarted() error
MarkToKill() error
MarkKilled() error
MarkFinished() error
MarkError() error
}
// LifeCycleHandler handles conveyor start/stop
type LifeCycleHandler interface {
ProgressUpdater
StateUpdater
}
func getStateMarker(state string, lch LifeCycleHandler) func() error {
switch state {
case StatusPreparing:
return lch.MarkPreparing
case StateStarted:
return lch.MarkStarted
case StateToKill:
return lch.MarkToKill
case StateKilled:
return lch.MarkKilled
case StateFinished:
return lch.MarkFinished
case StateInternalError:
return lch.MarkError
default:
return nil
}
}
type LocalLifeCycleHandler struct {
}