From fcc6aa8c681e05b27a41a9a3279e06cf7fb02735 Mon Sep 17 00:00:00 2001 From: simonzhangsz Date: Fri, 5 Jan 2024 20:01:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=8D=E8=83=BD=E5=91=A8=E6=9C=9F?= =?UTF-8?q?=E5=90=AF=E5=8A=A8getStateFromNE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../getStateFromNE/getStateFromNE.go | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/modules/crontask/processor/getStateFromNE/getStateFromNE.go b/src/modules/crontask/processor/getStateFromNE/getStateFromNE.go index 054cc726..c3b2091b 100644 --- a/src/modules/crontask/processor/getStateFromNE/getStateFromNE.go +++ b/src/modules/crontask/processor/getStateFromNE/getStateFromNE.go @@ -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), ¶ms) - // // // if err == nil { - // // // duration = params.Duration - // // // } + _ = json.Unmarshal([]byte(sysJob.TargetParams), ¶ms) + // 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)