- 修复UpdateActStatusByTime中的BUG

This commit is contained in:
gazebo
2019-08-05 16:59:30 +08:00
parent 4b6ed5200f
commit 539cfb31fe
4 changed files with 22 additions and 14 deletions

View File

@@ -81,31 +81,30 @@ func IsImportantTaskRunning(taskName string) bool {
func Init() {
if globals.IsProductEnv() {
ScheduleTimerFunc(doDailyWork, dailyWorkTimeList)
ScheduleTimerFunc("doDailyWork", doDailyWork, dailyWorkTimeList)
ScheduleTimerFuncByInterval(func() {
RefreshRealMobile(jxcontext.AdminCtx, model.VendorIDEBAI, time.Now().Add(-24*time.Hour), utils.DefaultTimeValue, false, true)
}, 5*time.Second, 1*time.Hour)
ScheduleTimerFunc(func() {
ScheduleTimerFunc("auto enable remote store", func() {
cms.EnableHaveRestStores(jxcontext.AdminCtx, false, true)
cms.OpenRemoteStoreByJxStatus(jxcontext.AdminCtx, nil, nil, false, false, true)
}, openRemoteStoreTimeList)
ScheduleTimerFunc(func() {
ScheduleTimerFunc("SaveAndSendAlarmVendorSnapshot", func() {
cms.SaveAndSendAlarmVendorSnapshot(jxcontext.AdminCtx, nil, nil, false)
}, cms.WatchVendorStoreTimeList)
ScheduleTimerFunc(func() {
ScheduleTimerFunc("RefreshPageActs", func() {
act.RefreshPageActs(jxcontext.AdminCtx, []int{model.VendorIDEBAI}, time.Now().Add(-30*24*time.Hour), false)
}, refreshPageActTimeList)
ScheduleTimerFunc(func() {
ScheduleTimerFunc("UpdateActStatusByTime", func() {
dao.UpdateActStatusByTime(dao.GetDB(), time.Now().Add(-48*time.Hour))
}, updateActStatusTimeList)
InitEx()
}
ScheduleTimerFunc(func() {
ScheduleTimerFunc("AutoSaleStoreSku", func() {
cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false)
}, autoSaleStoreSkuTimeList)
}
@@ -170,14 +169,15 @@ func RefreshRealMobile(ctx *jxcontext.Context, vendorID int, fromTime, toTime ti
return hint, err
}
func ScheduleTimerFunc(handler func(), timeList []string) {
func ScheduleTimerFunc(name string, handler func(), timeList []string) {
now := time.Now()
nextTime := jxutils.GetNextTimeFromList(now, timeList)
duration := nextTime.Sub(now) + 1*time.Second
globals.SugarLogger.Debugf("ScheduleTimerFunc, duration:%v", duration)
globals.SugarLogger.Debugf("ScheduleTimerFunc, func:%s, duration:%v", name, duration)
utils.AfterFuncWithRecover(duration, func() {
globals.SugarLogger.Debugf("ScheduleTimerFunc func:%s", name)
handler()
ScheduleTimerFunc(handler, timeList)
ScheduleTimerFunc(name, handler, timeList)
})
}

View File

@@ -165,12 +165,12 @@ func InitEx() {
startTimeList = startOpStoreTimeListJXGY
stopTimeList = endOpStoreTimeListJXGY
}
ScheduleTimerFunc(func() {
ScheduleTimerFunc("StartOpStore", func() {
if !IsImportantTaskRunning(TaskNameSyncStoreSku) {
StartOrEndOpStore(true, 0, 0, false, true)
}
}, startTimeList)
ScheduleTimerFunc(func() {
ScheduleTimerFunc("EndOpStore", func() {
if !IsImportantTaskRunning(TaskNameSyncStoreSku) {
StartOrEndOpStore(false, 0, 0, false, true)
}

View File

@@ -365,11 +365,12 @@ func UpdateActStatusByTime(db *DaoDB, refTime time.Time) (num int64, err error)
sql := `
UPDATE act t1
SET t1.status = ?
WHERE t1.status < ? AND t1.end_at < ?;`
WHERE t1.deleted_at = ? AND t1.status < ? AND t1.end_at < ?;`
sqlParams := []interface{}{
model.ActStatusEnded,
model.ActStatusCanceled,
utils.DefaultTimeValue,
model.ActStatusCanceled,
refTime,
}
num, err = ExecuteSQL(db, sql, sqlParams...)
return num, err

View File

@@ -58,3 +58,10 @@ func TestGetEffectiveActStoreSkuInfo(t *testing.T) {
}
}
}
func TestUpdateActStatusByTime(t *testing.T) {
_, err := UpdateActStatusByTime(GetDB(), time.Now().Add(-48*time.Hour))
if err != nil {
t.Fatal(err)
}
}