- replace all goroutine and AfterFunc with recover version

This commit is contained in:
gazebo
2019-03-15 10:26:30 +08:00
parent e5bf25bd04
commit dec14126a7
14 changed files with 30 additions and 29 deletions

View File

@@ -164,7 +164,7 @@ func (c *OrderManager) replyOrderComment(orderComment *model.OrderComment) (err
delaySeconds := config.delayGapBegin + rand.Intn(config.delayGapEnd-config.delayGapBegin)
content := config.comments[rand.Intn(len(config.comments))]
globals.SugarLogger.Debugf("replyOrderComment orderID:%s, delaySeconds:%d, content:%s", orderComment.VendorOrderID, delaySeconds, content)
time.AfterFunc(time.Duration(delaySeconds)*time.Second, func() {
utils.AfterFuncWithRecover(time.Duration(delaySeconds)*time.Second, func() {
if globals.ReallySendWeixinMsg {
if handler := partner.GetPurchasePlatformFromVendorID(orderComment.VendorID); handler != nil {
err = handler.ReplyOrderComment(jxcontext.AdminCtx, orderComment, content)

View File

@@ -583,7 +583,7 @@ func (s *DefScheduler) swtich2SelfDeliverWithRetry(savedOrderInfo *WatchOrderInf
if err := s.Swtich2SelfDeliver(order, ""); err != nil && err != scheduler.ErrOrderStatusAlreadySatisfyCurOperation {
globals.SugarLogger.Infof("swtich2SelfDeliverWithRetry failed, bill:%v, err:%v", bill, err)
if retryCount > 0 {
time.AfterFunc(duration, func() {
utils.AfterFuncWithRecover(duration, func() {
jxutils.CallMsgHandlerAsync(func() {
s.swtich2SelfDeliverWithRetry(savedOrderInfo, bill, retryCount-1, duration)
}, order.VendorOrderID)
@@ -724,7 +724,7 @@ func (s *DefScheduler) resetTimer(savedOrderInfo *WatchOrderInfo, bill *model.Wa
}
savedOrderInfo.timerStatusType = statusType
savedOrderInfo.timerStatus = status
savedOrderInfo.timer = time.AfterFunc(timeout, func() {
savedOrderInfo.timer = utils.AfterFuncWithRecover(timeout, func() {
jxutils.CallMsgHandlerAsync(func() {
globals.SugarLogger.Debugf("fire timer:%s, orderID:%s", timerName, order.VendorOrderID)
config.TimeoutAction(savedOrderInfo)

View File

@@ -14,7 +14,7 @@ func Init() {
func RefreshEbaiRealMobile() {
ebai.CurPurchaseHandler.RefreshRealMobile(jxcontext.AdminCtx, time.Now().Add(-6*time.Hour), utils.DefaultTimeValue, true, true)
time.AfterFunc(1*time.Hour, func() {
utils.AfterFuncWithRecover(1*time.Hour, func() {
RefreshEbaiRealMobile()
})
}

View File

@@ -205,7 +205,7 @@ func scheduleDailyRoutine(isFirst bool) {
UpdateJdPromotionStatus()
}
// globals.SugarLogger.Debug(duration)
time.AfterFunc(duration, func() {
utils.AfterFuncWithRecover(duration, func() {
UpdateJdPromotionStatus()
scheduleDailyRoutine(false)
})
@@ -213,12 +213,12 @@ func scheduleDailyRoutine(isFirst bool) {
func scheduleRoutine(isFirst bool) {
if isFirst {
go func() {
utils.CallFuncAsync(func() {
RefreshJdLockStoreSku()
RefreshJdStoreSkuStock(0, nil)
}()
})
}
time.AfterFunc(stockRefreshGap, func() {
utils.AfterFuncWithRecover(stockRefreshGap, func() {
RefreshJdLockStoreSku()
RefreshJdStoreSkuStock(0, nil)
scheduleRoutine(false)
@@ -887,7 +887,7 @@ func OnStoreStockMsg(msg *jdapi.CallbackStoreStockMsg) (retVal *jdapi.CallbackRe
sku := &model.Sku{}
sku.JdID = msg.SkuId
if err = dao.GetEntity(db, sku, model.FieldJdID); err == nil {
go func() {
utils.CallFuncAsync(func() {
if msg.Vendibility == 1 {
vendibility := &jdapi.StockVendibility{
OutSkuId: utils.Int2Str(sku.ID),
@@ -906,7 +906,7 @@ func OnStoreStockMsg(msg *jdapi.CallbackStoreStockMsg) (retVal *jdapi.CallbackRe
stock,
}, userName)
}
}()
})
}
}
return jdapi.Err2CallbackResponse(err, "")
@@ -917,7 +917,7 @@ func OnNewPromotionMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackRespo
}
func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.CallbackResponse) {
go func() {
utils.CallFuncAsync(func() {
result, err := api.JdAPI.QueryPromotionInfo(promotionInfoId)
if err == nil {
db := dao.GetDB()
@@ -1005,7 +1005,7 @@ func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.Callba
}
}
}
}()
})
return jdapi.Err2CallbackResponse(nil, "")
}

View File

@@ -40,7 +40,7 @@ func init() {
func (m *SyncMapWithTimeout) StoreWithTimeout(key, value interface{}, timeout time.Duration) {
m.Map.Store(key, value)
m.timers.Store(key, time.AfterFunc(timeout, func() {
m.timers.Store(key, utils.AfterFuncWithRecover(timeout, func() {
m.Delete(key)
}))
}

View File

@@ -291,9 +291,9 @@ func (c *PurchaseHandler) postFakeFinishedPickupMsg(vendorOrderID string) {
"order_id": vendorOrderID,
},
}
go func() {
utils.CallFuncAsync(func() {
OnCallbackMsg(msg)
}()
})
}
func getTimeFromTimestampStr(sendTime string) time.Time {

View File

@@ -21,14 +21,14 @@ const (
)
func (c *PurchaseHandler) StartRefreshComment() {
time.AfterFunc(5*time.Second, func() {
utils.AfterFuncWithRecover(5*time.Second, func() {
c.refreshCommentOnce()
})
}
func (c *PurchaseHandler) refreshCommentOnce() {
c.RefreshComment(time.Now().Add(-RefreshCommentTime), time.Now())
time.AfterFunc(RefreshCommentTimeInterval, func() {
utils.AfterFuncWithRecover(RefreshCommentTimeInterval, func() {
c.refreshCommentOnce()
})
}

View File

@@ -250,7 +250,7 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks
// 饿百支持创建sku时绑定商家分类了
// isCreate = true
// // 创建SKU后马上绑定分类会失败所以延迟绑定
// time.AfterFunc(3*time.Second, func() {
// utils.AfterFuncWithRecover(3*time.Second, func() {
// if err := api.EbaiAPI.SkuShopCategoryMap(strStoreID, storeSku.EbaiID, utils.Int64ToStr(storeSku.CatEbaiID)); err == nil {
// storeSku.EbaiSyncStatus = 0
// dao.UpdateEntity(nil, &storeSku.StoreSkuBind, updateFields...)

View File

@@ -16,7 +16,8 @@ const (
)
func (c *PurchaseHandler) ClientUrgeOrder(orderID string) (err error) {
go func() (err error) {
utils.CallFuncAsync(func() {
var err error
globals.SugarLogger.Debugf("ClientUrgeOrder orderID:%s", orderID)
order, err2 := partner.CurOrderManager.LoadOrder(orderID, model.VendorIDELM)
if err = err2; err == nil {
@@ -45,7 +46,6 @@ func (c *PurchaseHandler) ClientUrgeOrder(orderID string) (err error) {
if err != nil {
globals.SugarLogger.Warnf("ClientUrgeOrder orderID:%s failed with error:%v", orderID, err)
}
return err
}()
})
return err
}

View File

@@ -156,7 +156,7 @@ func (c *PurchaseHandler) replyOrderComment(intOrderID int64, jdStoreNo string,
delaySeconds := config.delayGapBegin + rand.Intn(config.delayGapEnd-config.delayGapBegin)
content := config.comments[rand.Intn(len(config.comments))]
globals.SugarLogger.Debugf("replyOrderComment orderID:%d, delaySeconds:%d, content:%s", intOrderID, delaySeconds, content)
time.AfterFunc(time.Duration(delaySeconds)*time.Second, func() {
utils.AfterFuncWithRecover(time.Duration(delaySeconds)*time.Second, func() {
// err2 := utils.CallFuncLogError(func() error {
// if globals.ReallyCallPlatformAPI {
// return api.JdAPI.OrgReplyComment(intOrderID, jdStoreNo, content, utils.GetAPIOperator(""))

View File

@@ -189,9 +189,9 @@ func (c *PurchaseHandler) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptI
msg.Data.Set("utime", msg.Data.Get("timestamp"))
msg.Data.Set(mtwmapi.KeyOrderID, order.VendorOrderID)
msg.Data.Set("status", mtwmapi.OrderStatusReceived)
go func() {
utils.CallFuncAsync(func() {
OnOrderCallbackMsg(msg)
}()
})
}
} else {
err = api.MtwmAPI.OrderCancel(utils.Str2Int64(order.VendorOrderID))

View File

@@ -40,9 +40,9 @@ func (c *PurchaseHandler) onWaybillMsg(msg *mtwmapi.CallbackMsg) (response *mtwm
msg.Data.Set("utime", msg.Data.Get("timestamp"))
msg.Data.Set(mtwmapi.KeyOrderID, waybill.VendorOrderID)
msg.Data.Set("status", mtwmapi.OrderStatusDelivering)
go func() {
utils.CallFuncAsync(func() {
OnOrderCallbackMsg(msg)
}()
})
}
return mtwmapi.Err2CallbackResponse(err, "")
}

View File

@@ -243,9 +243,9 @@ func (p *PurchaseHandler) postFakeMsg(orderNo int64, fakeStatus string) {
OrderNo: orderNo,
StatusTime: time.Now(),
}
go func() {
utils.CallFuncAsync(func() {
OnCallbackMsg(msg)
}()
})
}
func (p *PurchaseHandler) arrangeSaleStore(order *model.GoodsOrder, cityName, provinceName string) {

View File

@@ -7,6 +7,7 @@ import (
"time"
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch" // 导入缺省订单调度器
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
@@ -105,7 +106,7 @@ func main() {
// 延时的原因是等回调准备好
if beego.BConfig.RunMode == "prod" {
time.AfterFunc(2*time.Second, func() {
utils.AfterFuncWithRecover(2*time.Second, func() {
api.DingDingAPI.DeleteCallback()
if err := api.DingDingAPI.RegisterCallback([]string{dingdingapi.CBTagUserAddOrg, dingdingapi.CBTagUserModifyOrg, dingdingapi.CBTagUserLeaveOrg}, beego.AppConfig.DefaultString("dingdingCallbackToken", ""), beego.AppConfig.DefaultString("dingdingCallbackAESKey", ""), beego.AppConfig.DefaultString("dingdingCallbackURL", "")); err != nil {
globals.SugarLogger.Warnf("dingding RegisterCallback failed with error:%v", err)