i18n翻译
This commit is contained in:
@@ -2,12 +2,17 @@ package cron
|
||||
|
||||
import (
|
||||
"context"
|
||||
"epic/internal/dao"
|
||||
"epic/internal/model/entity"
|
||||
"epic/internal/service"
|
||||
"epic/internal/util"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcron"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Logic struct {
|
||||
@@ -168,6 +173,13 @@ func (l *Logic) registerDefaultJobs(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 每30分钟执行一次OSS预签名URL缓存刷新任务
|
||||
if err := l.AddJob(ctx, "oss_presignurl_refresh", "0 0/30 * * * *", func() {
|
||||
l.refreshOssPresignUrlCacheJob(ctx)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -244,3 +256,43 @@ func (l *Logic) refreshCache(ctx context.Context) {
|
||||
|
||||
g.Log().Info(ctx, "Cache refresh completed")
|
||||
}
|
||||
|
||||
// 刷新OSS图片预签名URL缓存的定时任务
|
||||
func (l *Logic) refreshOssPresignUrlCacheJob(ctx context.Context) {
|
||||
g.Log().Info(ctx, "Starting OSS presigned URL cache refresh...")
|
||||
|
||||
// 1. 从数据库读取所有英雄图片地址
|
||||
var dbHeroes []*entity.EpicHeroInfo
|
||||
err := dao.EpicHeroInfo.Ctx(ctx).Scan(&dbHeroes)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "Failed to query hero info for OSS presign refresh:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 2. 提取OSS图片key(去掉域名和bucket前缀)
|
||||
var keys []string
|
||||
for _, hero := range dbHeroes {
|
||||
headImgUrl := hero.HeadImgUrl
|
||||
if headImgUrl == "" {
|
||||
continue
|
||||
}
|
||||
// 只处理以http开头的图片地址
|
||||
// 例:https://s3.bitiful.net/bucket/epic/hero/xxx.png 或 https://bfoss.htoop.cn/epic/hero/xxx.png
|
||||
// 目标key: epic/hero/xxx.png
|
||||
key := ""
|
||||
if idx := strings.Index(headImgUrl, "/epic/hero/"); idx != -1 {
|
||||
key = headImgUrl[idx+1:]
|
||||
}
|
||||
if key != "" {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
}
|
||||
|
||||
expire := 1 * time.Hour // 预签名URL有效期
|
||||
err = util.RefreshOssPresignedUrlCache(ctx, keys, expire)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "OSS presigned URL cache refresh failed:", err)
|
||||
} else {
|
||||
g.Log().Info(ctx, "OSS presigned URL cache refresh completed")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user