add cron to loop
parent
c2ed541604
commit
f84614a8da
|
|
@ -1542,8 +1542,8 @@ function getGetParamValue(url, paramName) {
|
|||
prio: form.prio.value,
|
||||
tags: form.tags.value,
|
||||
duedate: form.duedate.value,
|
||||
loop: form.loop.value
|
||||
cron: form.cron.value
|
||||
loop: form.loop.value,
|
||||
cron: form.cron.value,
|
||||
}, function (json) {
|
||||
if (!parseInt(json.total)) return;
|
||||
form.task.value = '';
|
||||
|
|
|
|||
|
|
@ -90,12 +90,17 @@ func (a *Ajax) Async() {
|
|||
var err error
|
||||
nextDue := time.Now().Add(config.Loop)
|
||||
c := time.NewTicker(config.Loop)
|
||||
c2 := time.NewTicker(config.Loop)
|
||||
for {
|
||||
c.Stop()
|
||||
c.Reset(config.Loop)
|
||||
c2.Stop()
|
||||
c2.Reset(time.Until(nextDue))
|
||||
log.Println("next loop at", time.Until(nextDue), "or", config.Loop)
|
||||
select {
|
||||
case <-c.C:
|
||||
case <-time.After(time.Until(nextDue)):
|
||||
case <-c2.C:
|
||||
}
|
||||
log.Println("loop tasks")
|
||||
nextDue, err = a.loopTasks()
|
||||
if err != nil {
|
||||
log.Println("failed to loop tasks", err)
|
||||
|
|
@ -125,7 +130,10 @@ func (a *Ajax) loopTasks() (time.Time, error) {
|
|||
}
|
||||
nextLoopTrigger := task.Completed.Add(task.Loop)
|
||||
if task.Loop == 0 {
|
||||
nextLoopTrigger = task.Cron.Next()
|
||||
nextLoopTrigger2 := task.Cron.Next(task.Completed)
|
||||
if nextLoopTrigger2.Before(nextLoopTrigger) {
|
||||
nextLoopTrigger = nextLoopTrigger2
|
||||
}
|
||||
}
|
||||
if time.Now().Before(nextLoopTrigger) {
|
||||
if nextLoopTrigger.Before(nextDue) {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ import (
|
|||
|
||||
type Cron string
|
||||
|
||||
func (c Cron) Next() time.Time {
|
||||
func (c Cron) Next(since time.Time) time.Time {
|
||||
schedule, err := cron.ParseStandard(string(c))
|
||||
if err != nil {
|
||||
return time.Time{}
|
||||
}
|
||||
return schedule.Next(time.Now())
|
||||
return schedule.Next(since)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue