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