File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -131,8 +131,11 @@ func (c *Cron) Entries() []*Entry {
131
131
return c .entrySnapshot ()
132
132
}
133
133
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 .
135
135
func (c * Cron ) Start () {
136
+ if c .running {
137
+ return
138
+ }
136
139
c .running = true
137
140
go c .run ()
138
141
}
@@ -171,8 +174,9 @@ func (c *Cron) run() {
171
174
effective = c .entries [0 ].Next
172
175
}
173
176
177
+ timer := time .NewTimer (effective .Sub (now ))
174
178
select {
175
- case now = <- time . After ( effective . Sub ( now )) :
179
+ case now = <- timer . C :
176
180
// Run every entry whose next time was this effective time.
177
181
for _ , e := range c .entries {
178
182
if e .Next != effective {
@@ -193,11 +197,13 @@ func (c *Cron) run() {
193
197
c .snapshot <- c .entrySnapshot ()
194
198
195
199
case <- c .stop :
200
+ timer .Stop ()
196
201
return
197
202
}
198
203
199
204
// 'now' should be updated after newEntry and snapshot cases.
200
205
now = time .Now ().Local ()
206
+ timer .Stop ()
201
207
}
202
208
}
203
209
Original file line number Diff line number Diff line change @@ -114,6 +114,9 @@ func getRange(expr string, r bounds) uint64 {
114
114
if start > end {
115
115
log .Panicf ("Beginning of range (%d) beyond end of range (%d): %s" , start , end , expr )
116
116
}
117
+ if step == 0 {
118
+ log .Panicf ("Step of range should be a positive number: %s" , expr )
119
+ }
117
120
118
121
return getBits (start , end , step ) | extra_star
119
122
}
You can’t perform that action at this time.
0 commit comments