either of cron or loop can be set and unset, mark invalids as invalid and unfinish
parent
327fdb925c
commit
435ff82683
BIN
public.tar
BIN
public.tar
Binary file not shown.
|
|
@ -128,24 +128,30 @@ func (a *Ajax) loopTasks() (time.Time, error) {
|
|||
if task.Loop == 0 && task.Cron == "" {
|
||||
continue
|
||||
}
|
||||
nextLoopTrigger := task.Completed.Add(task.Loop)
|
||||
if task.Loop == 0 {
|
||||
nextLoopTrigger2 := task.Cron.Next(task.Completed)
|
||||
if nextLoopTrigger2.Before(nextLoopTrigger) {
|
||||
nextLoopTrigger = nextLoopTrigger2
|
||||
var nextTask time.Time
|
||||
if task.Loop > 0 {
|
||||
nextTask = task.Completed.Add(task.Loop)
|
||||
}
|
||||
if string(task.Cron) != "" {
|
||||
nextTask2 := task.Cron.Next(task.Completed)
|
||||
if nextTask2 != (time.Time{}) && (nextTask == (time.Time{}) || nextTask2.Before(nextTask)) {
|
||||
nextTask = nextTask2
|
||||
}
|
||||
}
|
||||
if time.Now().Before(nextLoopTrigger) {
|
||||
if nextLoopTrigger.Before(nextDue) {
|
||||
nextDue = nextLoopTrigger
|
||||
}
|
||||
continue
|
||||
}
|
||||
if time.Now().After(nextTask) {
|
||||
task.Complete = false
|
||||
task.Completed = time.Time{}
|
||||
if nextTask == (time.Time{}) {
|
||||
task.Title += " !!!INVALID CRON/LOOP!!!"
|
||||
}
|
||||
if err := a.storageSetTask(list.UUID, task); err != nil {
|
||||
return nextDue, err
|
||||
}
|
||||
} else {
|
||||
if nextTask.Before(nextDue) {
|
||||
nextDue = nextTask
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nextDue, nil
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package form
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
||||
|
|
@ -11,6 +12,7 @@ type Cron string
|
|||
func (c Cron) Next(since time.Time) time.Time {
|
||||
schedule, err := cron.ParseStandard(string(c))
|
||||
if err != nil {
|
||||
log.Printf("failed to parse cron %q: %v", string(c), err)
|
||||
return time.Time{}
|
||||
}
|
||||
return schedule.Next(since)
|
||||
|
|
|
|||
Loading…
Reference in New Issue