forked from coreos/fleet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.go
42 lines (34 loc) · 1.05 KB
/
state.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
package registry
import (
"path"
"github.com/coreos/fleet/job"
)
const (
statePrefix = "/state/"
)
// Get the current JobState of the provided Job
func (r *Registry) GetJobState(jobName string) *job.JobState {
key := path.Join(keyPrefix, statePrefix, jobName)
resp, err := r.etcd.Get(key, false, true)
// Assume the error was KeyNotFound and return an empty data structure
if err != nil {
return nil
}
var state job.JobState
//TODO: Handle the error generated by unmarshal
unmarshal(resp.Node.Value, &state)
return &state
}
// Persist the changes in a provided Machine's Job to etcd with the provided TTL
func (r *Registry) SaveJobState(jobName string, jobState *job.JobState) {
key := path.Join(keyPrefix, statePrefix, jobName)
//TODO: Handle the error generated by marshal
json, _ := marshal(jobState)
r.etcd.Set(key, json, 0)
}
// Delete the state from the Registry for the given Job
func (r *Registry) RemoveJobState(jobName string) error {
key := path.Join(keyPrefix, statePrefix, jobName)
_, err := r.etcd.Delete(key, false)
return err
}