either of cron or loop can be set and unset, mark invalids as invalid and unfinish

master
bel 2021-07-17 23:58:51 -06:00
parent 327fdb925c
commit 435ff82683
3 changed files with 22 additions and 14 deletions

Binary file not shown.

View File

@ -128,23 +128,29 @@ 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
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
}
continue
}
task.Complete = false
task.Completed = time.Time{}
if err := a.storageSetTask(list.UUID, task); err != nil {
return nextDue, err
}
}
}

View File

@ -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)