|
|
|
@ -5,7 +5,6 @@ import (
|
|
|
|
|
"b612.me/stardb"
|
|
|
|
|
"b612.me/startimer"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"sync"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
@ -69,23 +68,24 @@ func innerLoadDB(db *stardb.StarDB, callback func(task Task)) (*Remind, error) {
|
|
|
|
|
if len(res) != 0 {
|
|
|
|
|
rem.tasks = make(map[int64]Task, len(res))
|
|
|
|
|
for _, task := range res {
|
|
|
|
|
itask := new(Task)
|
|
|
|
|
*itask = task
|
|
|
|
|
tmr := startimer.NewTimer(time.Now())
|
|
|
|
|
err = tmr.ImportRepeats(task.TmrInfo)
|
|
|
|
|
err = tmr.ImportRepeats(itask.TmrInfo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
tmr.SetRunCountLimit(int(task.Limit))
|
|
|
|
|
task.timer = &tmr
|
|
|
|
|
task.timer.AddTask(func() {
|
|
|
|
|
rem.callbackFn(&task)
|
|
|
|
|
tmr.SetRunCountLimit(int(itask.Limit))
|
|
|
|
|
itask.timer = &tmr
|
|
|
|
|
itask.timer.AddTask(func() {
|
|
|
|
|
rem.callbackFn(itask)
|
|
|
|
|
})
|
|
|
|
|
err = task.timer.Run()
|
|
|
|
|
err = itask.timer.Run()
|
|
|
|
|
if err != nil {
|
|
|
|
|
db.Exec(`delete from remind where id=?`, task.ID)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
rem.tasks[task.ID] = task
|
|
|
|
|
fmt.Printf("%v %+v\n", tmr.NextTimer(), task)
|
|
|
|
|
rem.tasks[itask.ID] = *itask
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return &rem, nil
|
|
|
|
|