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 == "" { if task.Loop == 0 && task.Cron == "" {
continue continue
} }
nextLoopTrigger := task.Completed.Add(task.Loop) var nextTask time.Time
if task.Loop == 0 { if task.Loop > 0 {
nextLoopTrigger2 := task.Cron.Next(task.Completed) nextTask = task.Completed.Add(task.Loop)
if nextLoopTrigger2.Before(nextLoopTrigger) { }
nextLoopTrigger = nextLoopTrigger2 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 time.Now().After(nextTask) {
if nextLoopTrigger.Before(nextDue) { task.Complete = false
nextDue = nextLoopTrigger 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 package form
import ( import (
"log"
"time" "time"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"
@ -11,6 +12,7 @@ type Cron string
func (c Cron) Next(since time.Time) time.Time { func (c Cron) Next(since time.Time) time.Time {
schedule, err := cron.ParseStandard(string(c)) schedule, err := cron.ParseStandard(string(c))
if err != nil { if err != nil {
log.Printf("failed to parse cron %q: %v", string(c), err)
return time.Time{} return time.Time{}
} }
return schedule.Next(since) return schedule.Next(since)