forked from coreos/fleet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.go
47 lines (39 loc) · 869 Bytes
/
cache.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
package agent
import (
"encoding/json"
"github.com/coreos/fleet/job"
)
type agentCache map[string]job.JobState
func (ac *agentCache) MarshalJSON() ([]byte, error) {
type ds struct {
TargetStates map[string]job.JobState
}
data := ds{
TargetStates: map[string]job.JobState(*ac),
}
return json.Marshal(data)
}
func (ac *agentCache) setTargetState(jobName string, state job.JobState) {
(*ac)[jobName] = state
}
func (ac *agentCache) dropTargetState(jobName string) {
delete(*ac, jobName)
}
func (ac *agentCache) launchedJobs() []string {
jobs := make([]string, 0)
for j, ts := range *ac {
if ts == job.JobStateLaunched {
jobs = append(jobs, j)
}
}
return jobs
}
func (ac *agentCache) loadedJobs() []string {
jobs := make([]string, 0)
for j, ts := range *ac {
if ts == job.JobStateLoaded {
jobs = append(jobs, j)
}
}
return jobs
}