From b050c6bfa846b5e8aa445fe5c982db7e151bbf9a Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Thu, 19 Dec 2024 16:55:38 +0800 Subject: [PATCH] update --- ..._auto_delete_table_advertising_callback.go | 49 +++++++++++++++++++ .../svc_egg_energy_auto_update_user_access.go | 13 ++--- go.mod | 2 +- 3 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 app/task/svc/svc_auto_delete_table_advertising_callback.go diff --git a/app/task/svc/svc_auto_delete_table_advertising_callback.go b/app/task/svc/svc_auto_delete_table_advertising_callback.go new file mode 100644 index 0000000..1643bf9 --- /dev/null +++ b/app/task/svc/svc_auto_delete_table_advertising_callback.go @@ -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-------------------------------") +} diff --git a/app/task/svc/svc_egg_energy_auto_update_user_access.go b/app/task/svc/svc_egg_energy_auto_update_user_access.go index d38e6e9..9dabbd0 100644 --- a/app/task/svc/svc_egg_energy_auto_update_user_access.go +++ b/app/task/svc/svc_egg_energy_auto_update_user_access.go @@ -14,7 +14,7 @@ const deleteLimit = 1000 // EggEnergyAutoUpdateUserAccess 自动更新用户访问次数记录 func EggEnergyAutoUpdateUserAccess(engine *xorm.Engine) { - fmt.Println("svc_egg_energy_auto_update_user_access...") + fmt.Println("egg_energy_auto_update_user_access...") defer func() { if err := recover(); err != nil { fmt.Println(err) @@ -77,12 +77,13 @@ func EggEnergyAutoUpdateUserAccess(engine *xorm.Engine) { if affected < deleteLimit { break } + _, err = engine.Exec("OPTIMIZE table egg_access_records") + if err != nil { + fmt.Println("EggEnergyAutoUpdateUserAccess_OPTIMIZEFailed:::", err) + return + } } - _, err := engine.Exec("OPTIMIZE table egg_access_records") - if err != nil { - fmt.Println("EggEnergyAutoUpdateUserAccess_OPTIMIZEFailed:::", err) - return - } + fmt.Println("----------------------------EggEnergyAutoUpdateUserAccess_end-------------------------------") } diff --git a/go.mod b/go.mod index b429e86..5f8d07b 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( ) require ( - code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241216144119-b08da56ec5ec + code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241219083824-8eba71239d4f code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241217040418-3640cd7169f0 code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5