Browse Source

fix: add lock when AutoUpdateUserAccess

master
shenjiachi 23 hours ago
parent
commit
9710747f44
2 changed files with 9 additions and 1 deletions
  1. +9
    -0
      app/task/svc/svc_egg_energy_auto_update_user_access.go
  2. +0
    -1
      app/task/svc/svc_egg_energy_automatic_scoring.go

+ 9
- 0
app/task/svc/svc_egg_energy_auto_update_user_access.go View File

@@ -2,6 +2,7 @@ package svc

import (
"applet/app/utils"
"applet/app/utils/cache"
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es"
es2 "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
@@ -11,6 +12,7 @@ import (
)

const deleteLimit = 1000
const EggEnergyAutoUpdateUserAccessLockKey = "egg_energy_auto_update_user_access_lock_key"

// EggEnergyAutoUpdateUserAccess 自动更新用户访问次数记录
func EggEnergyAutoUpdateUserAccess(engine *xorm.Engine) {
@@ -28,6 +30,13 @@ func EggEnergyAutoUpdateUserAccess(engine *xorm.Engine) {
//TODO::只在凌晨两点 ~ 凌晨六点运行
return
}
getString, _ := cache.GetString(EggEnergyAutoUpdateUserAccessLockKey)
if getString != "" {
fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", "上一次蛋蛋分统计未执行完")
return
}
cache.SetEx(EggEnergyAutoUpdateUserAccessLockKey, "running", 4*60*60) // 4 h
defer cache.Del(EggEnergyAutoUpdateUserAccessLockKey)

// 获取当周信息
year, week := time.Now().ISOWeek()


+ 0
- 1
app/task/svc/svc_egg_energy_automatic_scoring.go View File

@@ -38,7 +38,6 @@ func EggEnergyAutomaticScoring(engine *xorm.Engine) {
defer cache.Del(EggEnergyAutomaticScoringLockKey)

now := time.Now()
fmt.Println(now.Hour())
weekday := now.Weekday()
if !(weekday != time.Wednesday && now.Hour() >= 0 && now.Hour() < 4) {
//TODO::只在周三凌晨零点 ~ 凌晨六点运行 (预计六点可以全部更新完,减少查询次数)


Loading…
Cancel
Save