Skip to content

Commit

Permalink
Update - commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nicojwzhang committed Jul 27, 2021
1 parent 837351e commit 54b7e29
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 2,057 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 // indirect
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e // indirect
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273 // indirect
github.com/robfig/cron/v3 v3.0.0 // indirect
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af
github.com/sirupsen/logrus v1.0.6 // indirect
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e h1:n/3MEhJQjQxrO
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273 h1:agujYaXJSxSo18YNX3jzl+4G6Bstwt+kqv47GS12uL0=
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/robfig/cron/v3 v3.0.0 h1:kQ6Cb7aHOHTSzNVNEhmp8EcWKLb4CbiMW9h9VyIhO4E=
github.com/robfig/cron/v3 v3.0.0/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af h1:gu+uRPtBe88sKxUCEXRoeCvVG90TJmwhiqRpvdhQFng=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/sirupsen/logrus v1.0.6 h1:hcP1GmhGigz/O7h1WVUM5KklBp1JoNS9FggWKdj/j3s=
Expand Down
25 changes: 14 additions & 11 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (

client "github.com/coreos/etcd/clientv3"

cron "github.com/robfig/cron/v3"
"github.com/shunfei/cronsun/conf"
"github.com/shunfei/cronsun/log"
"github.com/shunfei/cronsun/node/cron"
"github.com/shunfei/cronsun/utils"
)

Expand Down Expand Up @@ -302,7 +302,7 @@ func (rule *JobRule) Valid() error {
return ErrNilRule
}

sch, err := cron.Parse(rule.Timer)
sch, err := cron.ParseStandard(rule.Timer)
if err != nil {
return fmt.Errorf("invalid JobRule[%s], parse err: %s", rule.Timer, err.Error())
}
Expand Down Expand Up @@ -343,33 +343,36 @@ func DeleteJob(group, id string) (resp *client.DeleteResponse, err error) {

// 获取所有任务
func GetJobs() (jobs map[string]*Job, err error) {
log.Debugf("")
resp, err := DefalutClient.Get(conf.Config.Cmd, client.WithPrefix())
if err != nil {
return
log.Errorf("DefalutClient.Get() failed, err:%s", err)
return jobs, err
}

count := len(resp.Kvs)
jobs = make(map[string]*Job, count)
if count == 0 {
return
log.Warnf("job count is 0")
return jobs, err
}

for _, j := range resp.Kvs {
job := new(Job)
if e := json.Unmarshal(j.Value, job); e != nil {
log.Warnf("job[%s] umarshal err: %s", string(j.Key), e.Error())
if err := json.Unmarshal(j.Value, job); err != nil {
log.Warnf("job[%s] umarshal err: %s", string(j.Key), err)
continue
}

if err := job.Valid(); err != nil {
log.Warnf("job[%s] is invalid: %s", string(j.Key), err.Error())
log.Warnf("job[%s] is invalid: %s", string(j.Key), err)
continue
}

job.alone()
jobs[job.ID] = job
}
return
return jobs, err
}

func WatchJobs() client.WatchChan {
Expand Down Expand Up @@ -422,7 +425,7 @@ func (j *Job) GetNextRunTime() time.Time {
return nextTime
}
for i, r := range j.Rules {
sch, err := cron.Parse(r.Timer)
sch, err := cron.ParseStandard(r.Timer)
if err != nil {
return nextTime
}
Expand Down Expand Up @@ -618,7 +621,7 @@ func (j *Job) Cmds(nid string, gs map[string]*Group) (cmds map[string]*Cmd) {
log.Debugf("nid:%s, gs:%+v", nid, gs)
cmds = make(map[string]*Cmd)
if j.Pause {
return
return cmds
}

LOOP_TIMER_CMD:
Expand All @@ -643,7 +646,7 @@ LOOP_TIMER_CMD:
}
}

return
return cmds
}

// 判断该job是否会在该节点上运行
Expand Down
21 changes: 0 additions & 21 deletions node/cron/LICENSE

This file was deleted.

2 changes: 0 additions & 2 deletions node/cron/README.md

This file was deleted.

34 changes: 0 additions & 34 deletions node/cron/at.go

This file was deleted.

89 changes: 0 additions & 89 deletions node/cron/at_test.go

This file was deleted.

27 changes: 0 additions & 27 deletions node/cron/constantdelay.go

This file was deleted.

54 changes: 0 additions & 54 deletions node/cron/constantdelay_test.go

This file was deleted.

Loading

0 comments on commit 54b7e29

Please sign in to comment.