Parcourir la source

Resolved merge conflicts with remote master

Wannes il y a 9 ans
Parent
commit
5a4c55775d
2 fichiers modifiés avec 11 ajouts et 2 suppressions
  1. 8 2
      cron.go
  2. 3 0
      parser.go

+ 8 - 2
cron.go

@@ -137,8 +137,11 @@ func (c *Cron) Location() *time.Location {
 	return c.location
 }
 
-// Start the cron scheduler in its own go-routine.
+// Start the cron scheduler in its own go-routine, or no-op if already started.
 func (c *Cron) Start() {
+	if c.running {
+		return
+	}
 	c.running = true
 	go c.run()
 }
@@ -177,8 +180,9 @@ func (c *Cron) run() {
 			effective = c.entries[0].Next
 		}
 
+		timer := time.NewTimer(effective.Sub(now))
 		select {
-		case now = <-time.After(effective.Sub(now)):
+		case now = <-timer.C:
 			// Run every entry whose next time was this effective time.
 			for _, e := range c.entries {
 				if e.Next != effective {
@@ -198,11 +202,13 @@ func (c *Cron) run() {
 			c.snapshot <- c.entrySnapshot()
 
 		case <-c.stop:
+			timer.Stop()
 			return
 		}
 
 		// 'now' should be updated after newEntry and snapshot cases.
 		now = time.Now().In(c.location)
+		timer.Stop()
 	}
 }
 

+ 3 - 0
parser.go

@@ -114,6 +114,9 @@ func getRange(expr string, r bounds) uint64 {
 	if start > end {
 		log.Panicf("Beginning of range (%d) beyond end of range (%d): %s", start, end, expr)
 	}
+	if step == 0 {
+		log.Panicf("Step of range should be a positive number: %s", expr)
+	}
 
 	return getBits(start, end, step) | extra_star
 }