Skip to content

Commit

Permalink
fix(pkg.tasker): sleep 100ms so abort can be bailed asap, remove dup msg
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed May 4, 2021
1 parent d7a58e6 commit d868920
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/tasker/tasker.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,12 @@ func (t *Tasker) Run() {
first := true
for !t.abort && !t.timeout {
ref, willTime := t.tickTimer(first)

t.gron.C.SetRef(ref)
if t.timeout {
if t.timeout || t.abort {
break
}

tasks := make(map[string]TaskFunc)
t.gron.C.SetRef(ref)
for expr, refs := range t.exprs {
if due, _ := t.gron.SegmentsDue(strings.Split(expr, " ")); !due {
continue
Expand Down Expand Up @@ -232,7 +231,6 @@ func (t *Tasker) doSetup() {
go func() {
<-sig
t.abort = true
t.wait()
}()
}

Expand All @@ -253,17 +251,19 @@ func (t *Tasker) tickTimer(first bool) (time.Time, bool) {
return now, willTime
}

dur := time.Duration(wait) * time.Second
next := now.Add(dur)
next := now.Add(time.Duration(wait) * time.Second)
willTime = timed && next.After(t.until)
if t.verbose && !willTime {
t.Log.Printf("[tasker] next tick on %s", next.Format(dateFormat))
}

if willTime {
dur = time.Duration(tickSec) - now.Sub(t.until)
next = now.Add(time.Duration(tickSec) - now.Sub(t.until))
}
for !t.abort && !t.timeout && t.now().Before(next) {
time.Sleep(100 * time.Millisecond)
}

time.Sleep(dur)
t.timeout = timed && next.After(t.until)

return next, willTime
Expand Down

0 comments on commit d868920

Please sign in to comment.