diff --git a/.travis.yml b/.travis.yml index e9f1f0c..5e9922f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ go: - 1.9 install: - go get -u github.com/coreos/etcd/clientv3 -- go get github.com/coreos/etcd/mvcc/mvccpb - go get github.com/rogpeppe/fastuuid - go get golang.org/x/net/context - go get gopkg.in/mgo.v2 diff --git a/group.go b/group.go index e2b99c0..a2ffeea 100644 --- a/group.go +++ b/group.go @@ -6,7 +6,6 @@ import ( "strings" client "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/mvcc/mvccpb" "github.com/shunfei/cronsun/conf" "github.com/shunfei/cronsun/log" @@ -65,10 +64,10 @@ func WatchGroups() client.WatchChan { return DefalutClient.Watch(conf.Config.Group, client.WithPrefix(), client.WithPrevKV()) } -func GetGroupFromKv(kv *mvccpb.KeyValue) (g *Group, err error) { +func GetGroupFromKv(key, value []byte) (g *Group, err error) { g = new(Group) - if err = json.Unmarshal(kv.Value, g); err != nil { - err = fmt.Errorf("group[%s] umarshal err: %s", string(kv.Key), err.Error()) + if err = json.Unmarshal(value, g); err != nil { + err = fmt.Errorf("group[%s] umarshal err: %s", string(key), err.Error()) } return } diff --git a/job.go b/job.go index 0cb4b8b..6abce69 100644 --- a/job.go +++ b/job.go @@ -16,7 +16,6 @@ import ( "golang.org/x/net/context" client "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/mvcc/mvccpb" "github.com/shunfei/cronsun/conf" "github.com/shunfei/cronsun/log" @@ -371,10 +370,10 @@ func WatchJobs() client.WatchChan { return DefalutClient.Watch(conf.Config.Cmd, client.WithPrefix()) } -func GetJobFromKv(kv *mvccpb.KeyValue) (job *Job, err error) { +func GetJobFromKv(key, value []byte) (job *Job, err error) { job = new(Job) - if err = json.Unmarshal(kv.Value, job); err != nil { - err = fmt.Errorf("job[%s] umarshal err: %s", string(kv.Key), err.Error()) + if err = json.Unmarshal(value, job); err != nil { + err = fmt.Errorf("job[%s] umarshal err: %s", string(key), err.Error()) return } diff --git a/node/node.go b/node/node.go index da6de2d..5c06a3b 100644 --- a/node/node.go +++ b/node/node.go @@ -364,7 +364,7 @@ func (n *Node) watchJobs() { for _, ev := range wresp.Events { switch { case ev.IsCreate(): - job, err := cronsun.GetJobFromKv(ev.Kv) + job, err := cronsun.GetJobFromKv(ev.Kv.Key, ev.Kv.Value) if err != nil { log.Warnf("err: %s, kv: %s", err.Error(), ev.Kv.String()) continue @@ -373,7 +373,7 @@ func (n *Node) watchJobs() { job.Init(n.ID) n.addJob(job, true) case ev.IsModify(): - job, err := cronsun.GetJobFromKv(ev.Kv) + job, err := cronsun.GetJobFromKv(ev.Kv.Key, ev.Kv.Value) if err != nil { log.Warnf("err: %s, kv: %s", err.Error(), ev.Kv.String()) continue @@ -396,7 +396,7 @@ func (n *Node) watchGroups() { for _, ev := range wresp.Events { switch { case ev.IsCreate(): - g, err := cronsun.GetGroupFromKv(ev.Kv) + g, err := cronsun.GetGroupFromKv(ev.Kv.Key, ev.Kv.Value) if err != nil { log.Warnf("err: %s, kv: %s", err.Error(), ev.Kv.String()) continue @@ -404,7 +404,7 @@ func (n *Node) watchGroups() { n.addGroup(g) case ev.IsModify(): - g, err := cronsun.GetGroupFromKv(ev.Kv) + g, err := cronsun.GetGroupFromKv(ev.Kv.Key, ev.Kv.Value) if err != nil { log.Warnf("err: %s, kv: %s", err.Error(), ev.Kv.String()) continue