This commit is contained in:
2025-11-16 21:44:50 +08:00
parent 148fa1f2bb
commit aa94b47773
6 changed files with 31 additions and 19 deletions

View File

@@ -51,7 +51,8 @@ func (app *Application) initializeSystemPlans(ctx context.Context) error {
// 1. 获取所有已存在的系统计划
existingPlans, _, err := app.Infra.repos.planRepo.ListPlans(appCtx, repository.ListPlansOptions{
PlanType: repository.PlanTypeFilterSystem,
PlanType: repository.PlanTypeFilterSystem,
IncludeAssociations: true,
}, 1, 99999) // 使用一个较大的 pageSize 来获取所有系统计划
if err != nil {
return fmt.Errorf("获取现有系统计划失败: %w", err)
@@ -123,11 +124,6 @@ func (app *Application) initializePeriodicSystemHealthCheckPlan(ctx context.Cont
}
}
// 重新设置所有任务的 ExecutionOrder
for i := range newTasks {
newTasks[i].ExecutionOrder = i + 1
}
predefinedPlan := &models.Plan{
Name: models.PlanNamePeriodicSystemHealthCheck,
Description: fmt.Sprintf("这是一个系统预定义的计划, 每 %d 分钟自动触发一次全量数据采集, 并进行阈值校验告警。", app.Config.Collection.Interval),
@@ -139,6 +135,9 @@ func (app *Application) initializePeriodicSystemHealthCheckPlan(ctx context.Cont
Tasks: newTasks,
}
// 刷新所有任务的 ExecutionOrder
predefinedPlan.ReorderSteps()
if foundExistingPlan, ok := existingPlanMap[predefinedPlan.Name]; ok {
// 如果计划存在,则进行无差别更新
logger.Infof("预定义计划 '%s' 已存在,正在进行无差别更新...", predefinedPlan.Name)
@@ -196,6 +195,11 @@ func (app *Application) initializeAlarmNotificationPlan(ctx context.Context, exi
},
}
err := predefinedPlan.Tasks[0].SaveParameters(app.Config.AlarmNotification.NotificationIntervals)
if err != nil {
return fmt.Errorf("序列化告警通知任务参数失败: %w", err)
}
if foundExistingPlan, ok := existingPlanMap[predefinedPlan.Name]; ok {
// 如果计划存在,则进行无差别更新
logger.Infof("预定义计划 '%s' 已存在,正在进行无差别更新...", predefinedPlan.Name)