Ejemplo n.º 1
0
 public Task Execute(IJobExecutionContext context)
 {
     try
     {
         var agents = _agentsRepository.GetAgentsList();
         for (int i = 0; i < agents.Count(); i++)
         {
             if (agents[i].Enabled)
             {
                 long           lastTime = _repository.GetLastTime(i);
                 DateTimeOffset fromTime = DateTimeOffset.FromUnixTimeSeconds(lastTime);
                 var            metrics  = _client.GetHddMetrics(new GetAllHddMetricsApiRequest()
                 {
                     AgentAddress = agents[i].AgentAddress,
                     FromTime     = fromTime,
                     ToTime       = DateTimeOffset.Now
                 });
                 if (metrics != null)
                 {
                     foreach (var metric in metrics.Metrics)
                     {
                         _repository.Create(new HddMetric()
                         {
                             AgentId = metric.AgentId,
                             Time    = metric.Time.ToUnixTimeSeconds(),
                             Value   = metric.Value
                         });
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
     }
     return(Task.CompletedTask);
 }