From cdc5ec75b34c78fca8623b3a665884a6d7938ce1 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 21 Aug 2019 17:22:02 +0800 Subject: [PATCH] + ScheduleTimerFuncOnce --- business/jxstore/misc/misc.go | 13 +++++++++++++ controllers/elm_order.go | 10 +++++----- controllers/weimob_callback.go | 10 ++++++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index e0ae31204..0a8775f81 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -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() { diff --git a/controllers/elm_order.go b/controllers/elm_order.go index f406e1922..d1d24a1a4 100644 --- a/controllers/elm_order.go +++ b/controllers/elm_order.go @@ -4,7 +4,6 @@ import ( "net/http" "git.rosy.net.cn/baseapi/platformapi/elmapi" - "git.rosy.net.cn/jx-callback/globals/api" "github.com/astaxie/beego" ) @@ -16,10 +15,11 @@ type ElemeController struct { // https://open.shop.ele.me/openapi/documents/httppushmethod func (c *ElemeController) Msg() { if c.Ctx.Input.Method() == http.MethodPost { - _, callbackResponse := api.ElmAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) - if callbackResponse == nil { - // callbackResponse = elm.OnCallbackMsg(obj) - } + callbackResponse := elmapi.SuccessResponse + // obj, callbackResponse := api.ElmAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) + // if callbackResponse == nil { + // callbackResponse = elm.OnCallbackMsg(obj) + // } c.Data["json"] = callbackResponse c.ServeJSON() } else if c.Ctx.Input.Method() == http.MethodGet { // 应用需要支持推送地址的GET访问,当GET请求访问时,请直接返回{“message”:“ok”},用于推送地址的可用性测试。 diff --git a/controllers/weimob_callback.go b/controllers/weimob_callback.go index 8fa360e68..8e8123ad7 100644 --- a/controllers/weimob_callback.go +++ b/controllers/weimob_callback.go @@ -1,6 +1,7 @@ package controllers import ( + "git.rosy.net.cn/baseapi/platformapi/weimobapi" "git.rosy.net.cn/jx-callback/business/jxutils/tasks" "git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals/api" @@ -13,10 +14,11 @@ type WeimobController struct { func (c *WeimobController) onCallbackMsg() { if true { //c.Ctx.Input.Method() == http.MethodPost { - _, callbackResponse := api.WeimobAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) - if callbackResponse == nil { - // callbackResponse = wsc.OnCallbackMsg(msg) - } + callbackResponse := weimobapi.SuccessResponse + // msg, callbackResponse := api.WeimobAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) + // if callbackResponse == nil { + // callbackResponse = wsc.OnCallbackMsg(msg) + // } c.Data["json"] = callbackResponse c.ServeJSON() } else {