+ 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 return hint, err
} }
// 按时间序列循环
func ScheduleTimerFunc(name string, handler func(), timeList []string) { func ScheduleTimerFunc(name string, handler func(), timeList []string) {
now := time.Now() now := time.Now()
nextTime := jxutils.GetNextTimeFromList(now, timeList) 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) { func ScheduleTimerFuncByInterval(handler func(), delay, inerval time.Duration) {
globals.SugarLogger.Debugf("ScheduleTimerFuncByInterval, delay:%v, inerval:%v", delay, inerval) globals.SugarLogger.Debugf("ScheduleTimerFuncByInterval, delay:%v, inerval:%v", delay, inerval)
utils.AfterFuncWithRecover(delay, func() { utils.AfterFuncWithRecover(delay, func() {

View File

@@ -4,7 +4,6 @@ import (
"net/http" "net/http"
"git.rosy.net.cn/baseapi/platformapi/elmapi" "git.rosy.net.cn/baseapi/platformapi/elmapi"
"git.rosy.net.cn/jx-callback/globals/api"
"github.com/astaxie/beego" "github.com/astaxie/beego"
) )
@@ -16,10 +15,11 @@ type ElemeController struct {
// https://open.shop.ele.me/openapi/documents/httppushmethod // https://open.shop.ele.me/openapi/documents/httppushmethod
func (c *ElemeController) Msg() { func (c *ElemeController) Msg() {
if c.Ctx.Input.Method() == http.MethodPost { if c.Ctx.Input.Method() == http.MethodPost {
_, callbackResponse := api.ElmAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) callbackResponse := elmapi.SuccessResponse
if callbackResponse == nil { // obj, callbackResponse := api.ElmAPI.GetCallbackMsg(c.Ctx.Input.RequestBody)
// callbackResponse = elm.OnCallbackMsg(obj) // if callbackResponse == nil {
} // callbackResponse = elm.OnCallbackMsg(obj)
// }
c.Data["json"] = callbackResponse c.Data["json"] = callbackResponse
c.ServeJSON() c.ServeJSON()
} else if c.Ctx.Input.Method() == http.MethodGet { // 应用需要支持推送地址的GET访问当GET请求访问时请直接返回{“message”:“ok”},用于推送地址的可用性测试。 } else if c.Ctx.Input.Method() == http.MethodGet { // 应用需要支持推送地址的GET访问当GET请求访问时请直接返回{“message”:“ok”},用于推送地址的可用性测试。

View File

@@ -1,6 +1,7 @@
package controllers package controllers
import ( import (
"git.rosy.net.cn/baseapi/platformapi/weimobapi"
"git.rosy.net.cn/jx-callback/business/jxutils/tasks" "git.rosy.net.cn/jx-callback/business/jxutils/tasks"
"git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api" "git.rosy.net.cn/jx-callback/globals/api"
@@ -13,10 +14,11 @@ type WeimobController struct {
func (c *WeimobController) onCallbackMsg() { func (c *WeimobController) onCallbackMsg() {
if true { //c.Ctx.Input.Method() == http.MethodPost { if true { //c.Ctx.Input.Method() == http.MethodPost {
_, callbackResponse := api.WeimobAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) callbackResponse := weimobapi.SuccessResponse
if callbackResponse == nil { // msg, callbackResponse := api.WeimobAPI.GetCallbackMsg(c.Ctx.Input.RequestBody)
// callbackResponse = wsc.OnCallbackMsg(msg) // if callbackResponse == nil {
} // callbackResponse = wsc.OnCallbackMsg(msg)
// }
c.Data["json"] = callbackResponse c.Data["json"] = callbackResponse
c.ServeJSON() c.ServeJSON()
} else { } else {