预警40
This commit is contained in:
parent
f7247315cf
commit
a51f5d7834
|
|
@ -30,6 +30,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
WarningBudgetCron CacheKey = "warning_budget_cron"
|
||||
WarningBudgetSendIncr CacheKey = "warning_budget_incr"
|
||||
)
|
||||
|
||||
|
|
@ -49,6 +50,7 @@ var CacheKeyMap = map[CacheKey]time.Duration{
|
|||
ProductQueryLockKey: 30 * time.Second,
|
||||
|
||||
WarningBudgetSendIncr: 3 * time.Hour,
|
||||
WarningBudgetCron: 5 * time.Minute,
|
||||
}
|
||||
|
||||
type Cache struct {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,11 @@ package service
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"time"
|
||||
"voucher/internal/biz/vo"
|
||||
)
|
||||
|
||||
func (s *VoucherService) CronWarningBudget(ctx context.Context) error {
|
||||
|
|
@ -24,6 +28,23 @@ func (s *VoucherService) CronWarningBudget(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
cv := vo.WarningBudgetCron.BuildCache([]string{""})
|
||||
|
||||
cacheValue, err2 := s.rdb.Rdb.Get(ctx, cv.Key).Result()
|
||||
|
||||
if err2 != nil && err2 != redis.Nil {
|
||||
return fmt.Errorf(fmt.Sprintf("warningBudget定时任务,notice 获取redis缓存%s异常:%v", cv.Key, err2))
|
||||
}
|
||||
|
||||
if len(cacheValue) > 0 {
|
||||
log.Error("warningBudget定时任务,notice 获取redis缓存存在,本台服务不做执行")
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := s.rdb.Rdb.Set(ctx, cv.Key, time.Now().Format(time.DateTime), cv.TTL).Err(); err != nil {
|
||||
return fmt.Errorf(fmt.Sprintf("warningBudget定时任务 设置redis缓存%s异常:%v", cv.Key, err))
|
||||
}
|
||||
|
||||
return s.cron.AddFunc(c.Command, func() {
|
||||
|
||||
s.VoucherBiz.CronWarningBudget(ctx)
|
||||
|
|
|
|||
Loading…
Reference in New Issue