- make defsch.time2Schedule3rdCarrier configable.
This commit is contained in:
@@ -4,12 +4,14 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/basesch"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/configindb"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/weixinmsg"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
@@ -21,8 +23,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
time2Delivered = 1 * time.Hour // 正常从下单到送达的时间。
|
||||
time2Schedule3rdCarrier = 20 * time.Minute // 京东要求5分钟后才能转自送,保险起见,设置为5分半钟
|
||||
time2Delivered = 1 * time.Hour // 正常从下单到送达的时间。
|
||||
time2Schedule3rdCarrier = 20 // 京东要求5分钟后才能转自送,保险起见,设置为5分半钟
|
||||
// time2Schedule3rdCarrierGap4OrderStatus = 3 * time.Minute // 京东要求是运单状态为待抢单且超时5分钟,但为了防止没有运单事件,所以就拣货完成事件开始算,添加3分钟
|
||||
time2AutoPickupMin = 15 * time.Minute
|
||||
time2AutoPickupGap = 5 * 60 //随机5分钟
|
||||
@@ -35,6 +37,8 @@ const (
|
||||
maxWaybillRetryCount = 3
|
||||
|
||||
orderMapStoreMaxTime = 4 * 24 * time.Hour // cache最长存储时间
|
||||
|
||||
time2Schedule3rdCarrierKey = "waitminute4mt"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -73,6 +77,7 @@ type StatusActionConfig struct {
|
||||
// 重要:此调度器要求同一定单的处理逻辑必须是序列化了的,不然会有并发问题
|
||||
type DefScheduler struct {
|
||||
basesch.BaseScheduler
|
||||
locker sync.RWMutex
|
||||
defWorkflowConfig []map[int]*StatusActionConfig
|
||||
orderMap jxutils.SyncMapWithTimeout
|
||||
}
|
||||
@@ -237,7 +242,7 @@ func init() {
|
||||
map[int]*StatusActionConfig{
|
||||
model.WaybillStatusNew: &StatusActionConfig{
|
||||
TimerType: scheduler.TimerTypeBaseStatusTime,
|
||||
Timeout: time2Schedule3rdCarrier,
|
||||
Timeout: time2Schedule3rdCarrier * time.Minute,
|
||||
TimeoutAction: func(savedOrderInfo *WatchOrderInfo) (err error) {
|
||||
if savedOrderInfo.storeDeliveryType != scheduler.StoreDeliveryTypeByStore { // 非自配置商家使用
|
||||
return sch.createWaybillOn3rdProviders(savedOrderInfo, nil)
|
||||
@@ -249,6 +254,15 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func Init() {
|
||||
configindb.WatchConfigChange(time2Schedule3rdCarrierKey, OnDefSchConfChanged)
|
||||
if configTime, err := configindb.GetConfig(time2Schedule3rdCarrierKey, utils.Int2Str(time2Schedule3rdCarrier)); err == nil {
|
||||
OnDefSchConfChanged(time2Schedule3rdCarrierKey, configTime)
|
||||
} else {
|
||||
globals.SugarLogger.Errorf("defsch Init, error:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 以下是订单
|
||||
func (s *DefScheduler) OnOrderNew(order *model.GoodsOrder, isPending bool) (err error) {
|
||||
globals.SugarLogger.Debugf("OnOrderNew orderID:%s", order.VendorOrderID)
|
||||
@@ -752,6 +766,10 @@ func (s *DefScheduler) handleAutoAcceptOrder(orderID string, vendorID int, userM
|
||||
|
||||
func (s *DefScheduler) mergeOrderStatusConfig(statusType, status int, purchaseVendorID int) (retVal *StatusActionConfig) {
|
||||
vendorTimeout := partner.GetPurchasePlatformFromVendorID(purchaseVendorID).GetStatusActionTimeout(statusType, status)
|
||||
s.locker.RLock()
|
||||
defer func() {
|
||||
s.locker.RUnlock()
|
||||
}()
|
||||
defConfig := s.defWorkflowConfig[statusType][status]
|
||||
if defConfig == nil {
|
||||
return nil
|
||||
@@ -809,3 +827,18 @@ func (s *DefScheduler) ProxyCancelWaybill(order *model.GoodsOrder, bill *model.W
|
||||
globals.SugarLogger.Debugf("ProxyCancelWaybill orderID:%s stop schedule, bypass CancelWaybill", order.VendorOrderID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func OnDefSchConfChanged(key, value string) {
|
||||
if key == time2Schedule3rdCarrierKey {
|
||||
waitMinutes := int(utils.Str2Int64WithDefault(value, time2Schedule3rdCarrier))
|
||||
if waitMinutes >= 0 {
|
||||
FixedScheduler.locker.Lock()
|
||||
defer func() {
|
||||
FixedScheduler.locker.Unlock()
|
||||
}()
|
||||
conf := FixedScheduler.defWorkflowConfig[1][model.WaybillStatusNew]
|
||||
conf.Timeout = time.Duration(waitMinutes) * time.Minute
|
||||
globals.SugarLogger.Debugf("defsch wait miniutes 4 3rd delivery changed to:%d", waitMinutes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user