ci(drone): 添加 Go 模块和构建缓存

- 在 restore cache 和 rebuild cache 步骤中添加了 go-mod-cache 和 go
This commit is contained in:
hxt
2025-07-17 20:25:50 +08:00
parent 9ef6ac9cdb
commit 0ad79c4f27
75 changed files with 1400 additions and 1745 deletions

View File

@@ -131,19 +131,19 @@ func (l *Logic) GetJobStatus(ctx context.Context, name string) (bool, error) {
// registerDefaultJobs 注册默认的定时任务
func (l *Logic) registerDefaultJobs(ctx context.Context) error {
// 每小时执行一次数据同步任务
if err := l.AddJob(ctx, "data_sync_hourly", "0 0 * * * *", func() {
l.syncDataFromThirdParty(ctx)
}); err != nil {
return err
}
// 每天凌晨2点执行数据清理任务
if err := l.AddJob(ctx, "data_cleanup_daily", "0 0 2 * * *", func() {
l.cleanupOldData(ctx)
}); err != nil {
return err
}
//// 每小时执行一次数据同步任务
//if err := l.AddJob(ctx, "data_sync_hourly", "0 0 * * * *", func() {
// l.syncDataFromThirdParty(ctx)
//}); err != nil {
// return err
//}
//
//// 每天凌晨2点执行数据清理任务
//if err := l.AddJob(ctx, "data_cleanup_daily", "0 0 2 * * *", func() {
// l.cleanupOldData(ctx)
//}); err != nil {
// return err
//}
// 每5分钟执行一次健康检查任务
if err := l.AddJob(ctx, "health_check", "0 0/5 * * * *", func() {
@@ -208,7 +208,7 @@ func (l *Logic) syncHeroData(ctx context.Context) {
g.Log().Info(ctx, "Hero data sync completed")
}
// syncArtifactData 同步神器数据
//同步神器数据
func (l *Logic) syncArtifactData(ctx context.Context) {
g.Log().Info(ctx, "Starting artifact data sync...")
@@ -220,18 +220,6 @@ func (l *Logic) syncArtifactData(ctx context.Context) {
g.Log().Info(ctx, "Artifact data sync completed")
}
// cleanupOldData 清理旧数据
func (l *Logic) cleanupOldData(ctx context.Context) {
g.Log().Info(ctx, "Starting data cleanup...")
// TODO: 实现数据清理逻辑
// 1. 删除过期的缓存数据
// 2. 清理过期的日志记录
// 3. 归档历史数据
g.Log().Info(ctx, "Data cleanup completed")
}
// healthCheck 健康检查
func (l *Logic) healthCheck(ctx context.Context) {
g.Log().Debug(ctx, "Performing health check...")

View File

@@ -54,20 +54,18 @@ func (t *ThirdPartyDataSync) SyncHeroData(ctx context.Context) error {
func (t *ThirdPartyDataSync) SyncArtifactData(ctx context.Context) error {
g.Log().Info(ctx, "开始同步神器数据...")
util.RedisCache.Set(ctx, "artifacts_all11", "asd", 0)
//从第三方API获取神器数据
artifactData, err := t.fetchArtifactDataFromAPI(ctx)
if err != nil {
g.Log().Error(ctx, "获取神器数据失败:", err)
return err
}
// 示例从第三方API获取神器数据
//artifactData, err := t.fetchArtifactDataFromAPI(ctx)
//if err != nil {
// g.Log().Error(ctx, "获取神器数据失败:", err)
// return err
//}
//
//// 处理并保存数据
//if err := t.processAndSaveArtifactData(ctx, artifactData); err != nil {
// g.Log().Error(ctx, "处理神器数据失败:", err)
// return err
//}
// 处理并保存数据
if err := t.processAndSaveArtifactData(ctx, artifactData); err != nil {
g.Log().Error(ctx, "处理神器数据失败:", err)
return err
}
g.Log().Info(ctx, "神器数据同步完成")
return nil
@@ -113,12 +111,9 @@ func (t *ThirdPartyDataSync) FetchHeroBuildsFromAPI(ctx context.Context, heroNam
"Content-Type": "application/json",
}
// 直接将角色名作为body
//bodyBytes := []byte(heroName)
heroNameEN := i18n.Zh2En(heroName)
fmt.Println(heroNameEN)
resp, err := t.client.Header(headers).Post(ctx, apiURL, "Argent Waves Hwayoung")
resp, err := t.client.Header(headers).Post(ctx, apiURL, heroNameEN)
if err != nil {
return "", fmt.Errorf("API请求失败: %v", err)
}
@@ -424,3 +419,61 @@ func (t *ThirdPartyDataSync) SyncAllData(ctx context.Context) error {
g.Log().Info(ctx, "所有第三方数据同步完成")
return nil
}
// RefreshHeroSetContentByHeroInfo 刷新单个角色配装字段
func (t *ThirdPartyDataSync) RefreshHeroSetContentByHeroInfo(ctx context.Context, heroName, heroCode, jsonStr string) error {
g.Log().Infof(ctx, "刷新角色配装: %s", heroName)
if len(jsonStr) > 200 {
_, err := dao.EpicHeroInfo.Ctx(ctx).
Where(dao.EpicHeroInfo.Columns().HeroCode, heroCode).
Data(g.Map{
dao.EpicHeroInfo.Columns().SetContentJson: jsonStr,
dao.EpicHeroInfo.Columns().SetUpdateTime: gtime.Now(),
}).
Update()
if err != nil {
g.Log().Errorf(ctx, "更新数据库失败: %s, err: %v", heroName, err)
return err
}
g.Log().Infof(ctx, "已更新: %s", heroName)
return nil
} else {
g.Log().Error(ctx, "配装数据无效(长度<=200): %s", heroName)
return fmt.Errorf("配装数据无效(长度<=200)")
}
}
// RefreshAllHeroSetContent 刷新所有角色配装字段
func (t *ThirdPartyDataSync) RefreshAllHeroSetContent(ctx context.Context) error {
g.Log().Info(ctx, "开始批量刷新所有角色配装字段...")
// 1. 查询所有角色按set_update_time正序排列为空的在最前面
var heroList []*entity.EpicHeroInfo
err := dao.EpicHeroInfo.Ctx(ctx).
OrderAsc("set_update_time").
Scan(&heroList)
if err != nil {
g.Log().Error(ctx, "查询epic_hero_info失败:", err)
return err
}
for i, epicHeroInfo := range heroList {
g.Log().Infof(ctx, "[%d/%d] 处理角色: %s", i+1, len(heroList), epicHeroInfo.HeroName)
jsonStr, err := t.FetchHeroBuildsFromAPI(ctx, epicHeroInfo.HeroName)
if err != nil {
g.Log().Errorf(ctx, "获取配装数据失败: %s, err: %v", epicHeroInfo.HeroName, err)
} else {
err = t.RefreshHeroSetContentByHeroInfo(ctx, epicHeroInfo.HeroName, epicHeroInfo.HeroCode, jsonStr)
}
// 远程接口有频率限制停顿10分钟
if i < len(heroList)-1 {
g.Log().Info(ctx, "等待10分钟...")
time.Sleep(10 * time.Minute)
}
if err != nil {
continue
}
}
g.Log().Info(ctx, "所有角色配装字段刷新完成")
return nil
}

View File

@@ -23,6 +23,15 @@ func TestMain(m *testing.M) {
os.Exit(code)
}
/**
* 测试同步英雄数据
*/
func TestI18n(t *testing.T) {
_ = i18n.RefreshI18n(context.Background())
fmt.Println(i18n.Zh2En("湖畔魔女泰妮布里雅"))
}
/**
* 测试同步英雄数据
*/

View File

@@ -150,6 +150,10 @@ func (l *Logic) GetHeroDetailByCode(ctx context.Context, code string) (*v1.HeroD
}
}
if fribbleHeroSet.JsonContent != "" {
err := thirdPartySync.RefreshHeroSetContentByHeroInfo(ctx, epicHeroInfo.HeroName, code, fribbleHeroSet.JsonContent)
if err != nil {
return nil, err
}
// 写入 Redis 缓存,永久
util.RedisCache.Set(ctx, cacheKey, fribbleHeroSet.JsonContent, 0)
}

View File

@@ -646,7 +646,7 @@ func (l *Logic) LoadFromDB(ctx context.Context) error {
// 重新构建缓存
l.cache = make(map[string]map[string]string)
// 新增同步数据库内容到I18nEnToZh备份
// 新增同步数据库内容到I18nEnToZh和I18nZhToEn备份
for _, m := range mappings {
if l.cache[m.Language] == nil {
l.cache[m.Language] = make(map[string]string)
@@ -654,6 +654,7 @@ func (l *Logic) LoadFromDB(ctx context.Context) error {
l.cache[m.Language][m.KeyName] = m.Value
if m.Language == "zh" {
I18nEnToZh[m.KeyName] = m.Value
I18nZhToEn[m.Value] = m.KeyName // 新增:同步反向映射
}
}