master
兔子 2 years ago
parent 96419e47fa
commit 0aaaa38e03

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

@ -49,7 +49,7 @@ func TestRemind(t *testing.T) {
}
fmt.Println("length of remind", len(r.ListTasks()))
if len(r.ListTasks()) < 2 {
tk, err := r.AddTask("每8秒提醒我吃饭", "干饭", []byte{1, 2, 3})
tk, err := r.AddTask("每10秒提醒我吃饭", "干饭", []byte{1, 2, 3})
if err != nil {
t.Fatal(err)
}

Loading…
Cancel
Save