shenjiachi 3 giorni fa
parent
commit
b050c6bfa8
3 ha cambiato i file con 57 aggiunte e 7 eliminazioni
  1. +49
    -0
      app/task/svc/svc_auto_delete_table_advertising_callback.go
  2. +7
    -6
      app/task/svc/svc_egg_energy_auto_update_user_access.go
  3. +1
    -1
      go.mod

+ 49
- 0
app/task/svc/svc_auto_delete_table_advertising_callback.go Vedi File

@@ -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-------------------------------")
}

+ 7
- 6
app/task/svc/svc_egg_energy_auto_update_user_access.go Vedi File

@@ -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-------------------------------")

}

+ 1
- 1
go.mod Vedi File

@@ -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


Caricamento…
Annulla
Salva