- async call some funcs in scheduleRoutine to avoid blocking

This commit is contained in:
gazebo
2018-11-10 09:32:34 +08:00
parent e664e9ea3f
commit 8cea399565

View File

@@ -198,31 +198,36 @@ func init() {
gob.Register([]*SkuPrice{}) gob.Register([]*SkuPrice{})
} }
func scheduleDailyRoutine() { func scheduleDailyRoutine(isFirst bool) {
executeTime := utils.GetCurDate().Add(24*time.Hour + 5*time.Minute) // 凌晨00:05执行 executeTime := utils.GetCurDate().Add(24*time.Hour + 5*time.Minute) // 凌晨00:05执行
duration := executeTime.Sub(time.Now()) duration := executeTime.Sub(time.Now())
if duration > 1*time.Hour { if isFirst && duration > 1*time.Hour {
UpdateJdPromotionStatus() UpdateJdPromotionStatus()
} }
// globals.SugarLogger.Debug(duration) // globals.SugarLogger.Debug(duration)
time.AfterFunc(duration, func() { time.AfterFunc(duration, func() {
UpdateJdPromotionStatus() UpdateJdPromotionStatus()
scheduleDailyRoutine() scheduleDailyRoutine(false)
}) })
} }
func scheduleRoutine() { func scheduleRoutine(isFirst bool) {
RefreshJdLockStoreSku() if isFirst {
RefreshJdStoreSkuStock() go func() {
RefreshJdLockStoreSku()
RefreshJdStoreSkuStock()
}()
}
time.AfterFunc(stockRefreshGap, func() { time.AfterFunc(stockRefreshGap, func() {
scheduleRoutine() RefreshJdLockStoreSku()
RefreshJdStoreSkuStock()
scheduleRoutine(false)
}) })
} }
func Init() { func Init() {
scheduleDailyRoutine() scheduleDailyRoutine(true)
scheduleRoutine() scheduleRoutine(true)
} }
func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueWhenError bool, vendorPromotionID string, params *PromotionParams, mapData map[string]interface{}) (hint string, err error) { func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueWhenError bool, vendorPromotionID string, params *PromotionParams, mapData map[string]interface{}) (hint string, err error) {