-
Notifications
You must be signed in to change notification settings - Fork 0
/
Service.go
50 lines (42 loc) · 870 Bytes
/
Service.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
package ServiceController
import (
"fmt"
"time"
"go.uber.org/zap"
)
type ServiceError struct {
Name string
Reason string
}
func (e ServiceError) Error() string {
if e.Name != "" {
return fmt.Sprintf("ServiceError (%s) : %s", e.Name, e.Reason)
}
return fmt.Sprintf("ServiceError %s", e.Reason)
}
type ServiceState int32
const (
_ ServiceState = iota
Undefined
Ready
Busy
Failed
)
func (s ServiceState) String() string {
return [...]string{"Zero", "Undefined", "Ready", "Busy", "Failed"}[s]
}
type Service interface {
Name() string
Init(logger *zap.Logger, config *ServiceConfig) error
New() Service
GetState() ServiceState
SetState(state ServiceState)
GetConfig() *ServiceConfig
Run() error
Stop() error
Log() *zap.Logger
SetLastRun(when time.Time)
GetLastRun() time.Time
SetLastRestart(when time.Time)
GetLastRestart() time.Time
}