forked from cloudfoundry/guardian
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstore.go
64 lines (50 loc) · 1.09 KB
/
store.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
package rundmc
import (
"strings"
"sync"
)
//go:generate counterfeiter . Properties
type Properties interface {
Set(handle string, key string, value string)
Get(handle string, key string) (string, bool)
}
type events struct {
props Properties
mu sync.Mutex
}
func NewEventStore(props Properties) *events {
return &events{
props: props,
}
}
func (e *events) OnEvent(handle, event string) error {
e.mu.Lock()
defer e.mu.Unlock()
events := append(e.Events(handle), event)
e.props.Set(handle, "rundmc.events", strings.Join(events, ","))
return nil
}
func (e *events) Events(handle string) []string {
if value, ok := e.props.Get(handle, "rundmc.events"); ok {
return strings.Split(value, ",")
}
return nil
}
type states struct {
props Properties
}
func NewStateStore(props Properties) *states {
return &states{
props: props,
}
}
func (s *states) StoreStopped(handle string) {
s.props.Set(handle, "rundmc.state", "stopped")
}
func (s *states) IsStopped(handle string) bool {
value, ok := s.props.Get(handle, "rundmc.state")
if !ok {
return false
}
return value == "stopped"
}