diff options
author | Unknwon <u@gogs.io> | 2015-08-18 04:03:11 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-08-18 04:03:11 +0800 |
commit | 6235bd1fe9ed15c9a889f72e4fe2880189963306 (patch) | |
tree | a17575d4b59a61b65b011486bdbbad74c84feaee /modules/cron/cron.go | |
parent | 71fd10dd37af16ce540ae151b51faffbc3ef2d84 (diff) | |
download | gitea-6235bd1fe9ed15c9a889f72e4fe2880189963306.tar.gz gitea-6235bd1fe9ed15c9a889f72e4fe2880189963306.zip |
work on #986 and fix a LDAP crash
Diffstat (limited to 'modules/cron/cron.go')
-rw-r--r-- | modules/cron/cron.go | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/modules/cron/cron.go b/modules/cron/cron.go index dbf0174b86..3491afac99 100644 --- a/modules/cron/cron.go +++ b/modules/cron/cron.go @@ -91,34 +91,33 @@ type FuncJob func() func (f FuncJob) Run() { f() } // AddFunc adds a func to the Cron to be run on the given schedule. -func (c *Cron) AddFunc(desc, spec string, cmd func()) error { +func (c *Cron) AddFunc(desc, spec string, cmd func()) (*Entry, error) { return c.AddJob(desc, spec, FuncJob(cmd)) } // AddFunc adds a Job to the Cron to be run on the given schedule. -func (c *Cron) AddJob(desc, spec string, cmd Job) error { +func (c *Cron) AddJob(desc, spec string, cmd Job) (*Entry, error) { schedule, err := Parse(spec) if err != nil { - return err + return nil, err } - c.Schedule(desc, spec, schedule, cmd) - return nil + return c.Schedule(desc, spec, schedule, cmd), nil } // Schedule adds a Job to the Cron to be run on the given schedule. -func (c *Cron) Schedule(desc, spec string, schedule Schedule, cmd Job) { +func (c *Cron) Schedule(desc, spec string, schedule Schedule, cmd Job) *Entry { entry := &Entry{ Description: desc, Spec: spec, Schedule: schedule, Job: cmd, } - if !c.running { + if c.running { + c.add <- entry + } else { c.entries = append(c.entries, entry) - return } - - c.add <- entry + return entry } // Entries returns a snapshot of the cron entries. |