+ ScheduleTimerFuncOnce

This commit is contained in:
gazebo
2019-08-21 17:22:02 +08:00
parent 5e94bf4dbd
commit cdc5ec75b3
3 changed files with 24 additions and 9 deletions

View File

@@ -169,6 +169,7 @@ func RefreshRealMobile(ctx *jxcontext.Context, vendorID int, fromTime, toTime ti
return hint, err
}
// 按时间序列循环
func ScheduleTimerFunc(name string, handler func(), timeList []string) {
now := time.Now()
nextTime := jxutils.GetNextTimeFromList(now, timeList)
@@ -181,6 +182,18 @@ func ScheduleTimerFunc(name string, handler func(), timeList []string) {
})
}
// 按时间调度一次
func ScheduleTimerFuncOnce(name string, handler func(), timeStr string) {
now := time.Now()
nextTime := jxutils.GetNextTimeFromList(now, []string{timeStr})
duration := nextTime.Sub(now) + 1*time.Second
globals.SugarLogger.Debugf("ScheduleTimerFuncOnce, func:%s, duration:%v", name, duration)
utils.AfterFuncWithRecover(duration, func() {
globals.SugarLogger.Debugf("ScheduleTimerFuncOnce func:%s", name)
handler()
})
}
func ScheduleTimerFuncByInterval(handler func(), delay, inerval time.Duration) {
globals.SugarLogger.Debugf("ScheduleTimerFuncByInterval, delay:%v, inerval:%v", delay, inerval)
utils.AfterFuncWithRecover(delay, func() {