fix: 不能周期启动getStateFromNE

This commit is contained in:
2024-01-05 20:01:43 +08:00
parent 3cd8dd70a7
commit fcc6aa8c68

View File

@@ -10,6 +10,7 @@ import (
"ems.agt/lib/dborm"
"ems.agt/lib/log"
"ems.agt/restagent/config"
"ems.agt/src/framework/cron"
"github.com/go-resty/resty/v2"
)
@@ -68,36 +69,22 @@ type SystemState struct {
var client = resty.New()
func init() {
/*
client.
SetTimeout(10 * time.Second).
SetRetryCount(1).
SetRetryWaitTime(1 * time.Second).
SetRetryMaxWaitTime(2 * time.Second).
SetRetryAfter(func(client *resty.Client, resp *resty.Response) (time.Duration, error) {
return 0, errors.New("quota exceeded")
})
*/
client.
SetTimeout(time.Duration(400 * time.Millisecond))
// SetRetryCount(1).
// SetRetryWaitTime(time.Duration(1 * time.Second)).
// SetRetryMaxWaitTime(time.Duration(2 * time.Second))
//client.SetTimeout(2 * time.Second)
}
func (s *BarProcessor) Execute(data any) (any, error) {
var err error
s.count++
// options := data.(cron.JobData)
// // sysJob := options.SysJob
// // var params BarParams
options := data.(cron.JobData)
sysJob := options.SysJob
var params BarParams
// // // err := json.Unmarshal([]byte(sysJob.TargetParams), &params)
// // // if err == nil {
// // // duration = params.Duration
// // // }
_ = json.Unmarshal([]byte(sysJob.TargetParams), &params)
// if err == nil {
// duration = params.Duration
// }
var nes []dborm.NeInfo
_, err = dborm.XormGetAllNeInfo(&nes)
@@ -112,7 +99,7 @@ func (s *BarProcessor) Execute(data any) (any, error) {
requestURI := fmt.Sprintf("/api/rest/systemManagement/v1/elementType/%s/objectType/systemState", strings.ToLower(ne.NeType))
requestURL := fmt.Sprintf("http://%s:%s%s", ne.Ip, ne.Port, requestURI)
log.Debug("requestURL: Get", requestURL)
client := resty.New()
//client := resty.New()
response, err := client.R().
EnableTrace().
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
@@ -130,13 +117,17 @@ func (s *BarProcessor) Execute(data any) (any, error) {
log.Trace("response body:", string(response.Body()))
state := new(SystemState)
_ = json.Unmarshal(response.Body(), &state)
var dateStr *string = nil
if state.ExpiryDate != "" {
dateStr = &state.ExpiryDate
}
neState := new(dborm.NeState)
neState.NeType = ne.NeType
neState.NeId = ne.NeId
neState.Version = state.Version
neState.Capability = state.Capability
neState.SerialNum = state.SerialNum
neState.ExpiryDate = state.ExpiryDate
neState.ExpiryDate = *dateStr
cu, _ := json.Marshal(state.CpuUsage)
neState.CpuUsage = string(cu)
mu, _ := json.Marshal(state.MemUsage)