Allow tasks to schedule themselves in-task

This commit is contained in:
Daniel 2022-04-26 14:35:52 +02:00
parent 7797a54d18
commit 3f8f50ad1f

View file

@ -351,7 +351,7 @@ func (t *Task) executeWithLocking() {
t.executing = false
// repeat?
if t.isActive() && t.repeat != 0 {
if t.isActive() && t.repeat != 0 && t.executeAt.IsZero() {
t.executeAt = time.Now().Add(t.repeat)
t.addToSchedule(false)
}
@ -366,6 +366,9 @@ func (t *Task) executeWithLocking() {
t.lock.Unlock()
}()
// reset executeAt to detect if task set next execution itself
t.executeAt = time.Time{}
// run
err := t.taskFn(t.ctx, t)
if err != nil {