Пример #1
0
      public async Task Execute(IJobExecutionContext context)
      {
          var agents = _agentsRepository.GetActiveAgents();

          // асинхронно собираем метрики
          var listMetrics = await Task.WhenAll(agents.Select(async agent =>
            {
                var toTime   = DateTimeOffset.UtcNow;
                var fromTime = _metricsRepository.GetDateUpdate(agent.Id);
                var response = await GetMetricsByPeriod(agent, fromTime, toTime);
                return(response.Select(metric => new HddSpaceMetric()
                {
                    AgentId = agent.Id,
                    Time = metric.Time,
                    Value = metric.Value
                }));
            }));

          // сохраняем метрики
          foreach (var metrics in listMetrics)
          {
              foreach (var metric in metrics)
              {
                  _metricsRepository.Create(metric);
              }
          }
      }