Skip to content

Commit 7f3990a

Browse files
committed
Merge branch 'master' of https://github.com/robfig/cron
2 parents 96040e4 + 3625689 commit 7f3990a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

cron.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ func (c *Cron) Entries() []*Entry {
131131
return c.entrySnapshot()
132132
}
133133

134-
// Start the cron scheduler in its own go-routine.
134+
// Start the cron scheduler in its own go-routine, or no-op if already started.
135135
func (c *Cron) Start() {
136+
if c.running {
137+
return
138+
}
136139
c.running = true
137140
go c.run()
138141
}
@@ -171,8 +174,9 @@ func (c *Cron) run() {
171174
effective = c.entries[0].Next
172175
}
173176

177+
timer := time.NewTimer(effective.Sub(now))
174178
select {
175-
case now = <-time.After(effective.Sub(now)):
179+
case now = <-timer.C:
176180
// Run every entry whose next time was this effective time.
177181
for _, e := range c.entries {
178182
if e.Next != effective {
@@ -193,11 +197,13 @@ func (c *Cron) run() {
193197
c.snapshot <- c.entrySnapshot()
194198

195199
case <-c.stop:
200+
timer.Stop()
196201
return
197202
}
198203

199204
// 'now' should be updated after newEntry and snapshot cases.
200205
now = time.Now().Local()
206+
timer.Stop()
201207
}
202208
}
203209

parser.go

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ func getRange(expr string, r bounds) uint64 {
114114
if start > end {
115115
log.Panicf("Beginning of range (%d) beyond end of range (%d): %s", start, end, expr)
116116
}
117+
if step == 0 {
118+
log.Panicf("Step of range should be a positive number: %s", expr)
119+
}
117120

118121
return getBits(start, end, step) | extra_star
119122
}

0 commit comments

Comments
 (0)