fix: 定时任务配置数据上报
This commit is contained in:
56
src/modules/nms_cxy/processor/config/config.go
Normal file
56
src/modules/nms_cxy/processor/config/config.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"nms_cxy/src/framework/cron"
|
||||||
|
"nms_cxy/src/framework/logger"
|
||||||
|
"nms_cxy/src/modules/nms_cxy/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
var NewProcessor = &ConfigProcessor{
|
||||||
|
count: 0,
|
||||||
|
configService: service.NewConfigImpl,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 配置上报 队列任务处理
|
||||||
|
type ConfigProcessor struct {
|
||||||
|
// 执行次数
|
||||||
|
count int
|
||||||
|
// 配置数据处理服务
|
||||||
|
configService service.IConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ConfigProcessor) Execute(data any) (any, error) {
|
||||||
|
logger.Infof("执行 %d 次", s.count)
|
||||||
|
s.count++
|
||||||
|
|
||||||
|
options := data.(cron.JobData)
|
||||||
|
sysJob := options.SysJob
|
||||||
|
logger.Infof("重复 %v 任务ID %s", options.Repeat, sysJob.JobID)
|
||||||
|
|
||||||
|
// 读取参数值
|
||||||
|
var params struct {
|
||||||
|
NeTypes []string `json:"neTypes"`
|
||||||
|
}
|
||||||
|
err := json.Unmarshal([]byte(sysJob.TargetParams), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("json params 'neTypes' err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 遍历网元
|
||||||
|
for _, neType := range params.NeTypes {
|
||||||
|
err = s.configService.ConfigUploadOSS(neType)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回结果,用于记录执行结果
|
||||||
|
result := map[string]any{
|
||||||
|
"repeat": options.Repeat,
|
||||||
|
"count": s.count,
|
||||||
|
"jobName": sysJob.JobName,
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@@ -38,7 +38,7 @@ func (s *PerformanceProcessor) Execute(data any) (any, error) {
|
|||||||
}
|
}
|
||||||
err := json.Unmarshal([]byte(sysJob.TargetParams), ¶ms)
|
err := json.Unmarshal([]byte(sysJob.TargetParams), ¶ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("json params 'interval' err: %v", err)
|
return nil, fmt.Errorf("json params 'neTypes' err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 当前时间减去周期时间
|
// 当前时间减去周期时间
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"nms_cxy/src/framework/cron"
|
"nms_cxy/src/framework/cron"
|
||||||
|
"nms_cxy/src/modules/nms_cxy/processor/config"
|
||||||
"nms_cxy/src/modules/nms_cxy/processor/performance"
|
"nms_cxy/src/modules/nms_cxy/processor/performance"
|
||||||
"nms_cxy/src/modules/nms_cxy/processor/resource"
|
"nms_cxy/src/modules/nms_cxy/processor/resource"
|
||||||
)
|
)
|
||||||
@@ -10,4 +11,5 @@ import (
|
|||||||
func InitCronQueue() {
|
func InitCronQueue() {
|
||||||
cron.CreateQueue("performance_upload_oss", performance.NewProcessor)
|
cron.CreateQueue("performance_upload_oss", performance.NewProcessor)
|
||||||
cron.CreateQueue("resource_upload_oss", resource.NewProcessor)
|
cron.CreateQueue("resource_upload_oss", resource.NewProcessor)
|
||||||
|
cron.CreateQueue("config_upload_oss", config.NewProcessor)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func (s *ResourceProcessor) Execute(data any) (any, error) {
|
|||||||
}
|
}
|
||||||
err := json.Unmarshal([]byte(sysJob.TargetParams), ¶ms)
|
err := json.Unmarshal([]byte(sysJob.TargetParams), ¶ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("json params 'interval' err: %v", err)
|
return nil, fmt.Errorf("json params 'neTypes' err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 遍历网元
|
// 遍历网元
|
||||||
|
|||||||
Reference in New Issue
Block a user