|
|
@@ -0,0 +1,49 @@ |
|
|
|
package svc |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" |
|
|
|
"fmt" |
|
|
|
"time" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
const advertisingCallbackDeleteLimit = 2 |
|
|
|
|
|
|
|
// AutoDeleteTableAdvertisingCallback 自动清除七天前 advertising_callback 表数据 |
|
|
|
func AutoDeleteTableAdvertisingCallback(engine *xorm.Engine) { |
|
|
|
fmt.Println("auto_delete_table_advertising_callback.go...") |
|
|
|
defer func() { |
|
|
|
if err := recover(); err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
return |
|
|
|
} |
|
|
|
}() |
|
|
|
fmt.Println("----------------------------AutoDeleteTableAdvertisingCallback_begin-------------------------------") |
|
|
|
|
|
|
|
now := time.Now() |
|
|
|
if !(now.Hour() >= 2 && now.Hour() < 6) { |
|
|
|
//TODO::只在凌晨两点 ~ 凌晨六点运行 |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
for { |
|
|
|
// 删除七天之前的数据 |
|
|
|
toDeleteDateStr := now.AddDate(0, 0, -7).Format("2006-01-02 15:04:05") |
|
|
|
recordsDb := implement.NewAdvertisingCallbackDb(engine) |
|
|
|
affected, err := recordsDb.AdvertisingCallbackDeleteByDateByPage(toDeleteDateStr, advertisingCallbackDeleteLimit) |
|
|
|
if err != nil { |
|
|
|
fmt.Println("AutoDeleteTableAdvertisingCallback_DeleteAdvertisingCallbackFailed:::", err) |
|
|
|
return |
|
|
|
} |
|
|
|
if affected < advertisingCallbackDeleteLimit { |
|
|
|
break |
|
|
|
} |
|
|
|
_, err = engine.Exec("OPTIMIZE table advertising_callback") |
|
|
|
if err != nil { |
|
|
|
fmt.Println("AutoDeleteTableAdvertisingCallback_OPTIMIZEFailed:::", err) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fmt.Println("---------------------------AutoDeleteTableAdvertisingCallback_end-------------------------------") |
|
|
|
} |