- 用SyncMapWithTimeout管理tasksch任务

This commit is contained in:
gazebo
2019-08-07 14:55:54 +08:00
parent 8768fe8236
commit f06456cec1
3 changed files with 40 additions and 34 deletions

View File

@@ -9,7 +9,6 @@ import (
"regexp"
"sort"
"strings"
"sync"
"time"
"git.rosy.net.cn/baseapi/platformapi/autonavi"
@@ -27,11 +26,6 @@ var (
skuNamePat *regexp.Regexp
)
type SyncMapWithTimeout struct {
sync.Map
timers sync.Map
}
type OrderSkuList []*model.OrderSku
func (l OrderSkuList) Len() int {
@@ -60,22 +54,6 @@ func init() {
skuNamePat = regexp.MustCompile(`([\(\[【][^\(\[【\)\]】]*[\)\]】])?(.*?)([(].*[)])?\s*约?([1-9][\d\.]*)(g|G|kg|kG|Kg|KG|l|L|ml|mL|Ml|ML|克)\s*([(].*[)])?\s*(?:\/||)\s*([^\s()]{0,2})\s*([(].*[)])?$`)
}
func (m *SyncMapWithTimeout) StoreWithTimeout(key, value interface{}, timeout time.Duration) {
m.Map.Store(key, value)
m.timers.Store(key, utils.AfterFuncWithRecover(timeout, func() {
m.Delete(key)
}))
}
func (m *SyncMapWithTimeout) Delete(key interface{}) {
m.Map.Delete(key)
if value, ok := m.timers.Load(key); ok {
timer := value.(*time.Timer)
timer.Stop()
}
m.timers.Delete(key)
}
func getJxStoreIDFromOrder(order *model.GoodsOrder) (retVal int) {
if order.JxStoreID != 0 {
return order.JxStoreID