Merge pull request #159 from safing/fix/custom-task-scheduling

Allow tasks to schedule themselves in-task
This commit is contained in:
Daniel 2022-04-26 15:28:22 +02:00 committed by GitHub
commit 85f8832911
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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 {