Esempio n. 1
0
        public async Task <IActionResult> SendStatusAsync([FromBody] StatusLog sl)
        {
            _storeService.AddStatusLog(sl);
            await _storeService.SaveChangesAsync();

            return(Ok());
        }
Esempio n. 2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("ServiceChecker tracking {count} services at: {time}",
                                       _businessServices.Count(), DateTimeOffset.Now);

                var listOfTasks = new List <(Task <HttpResponseMessage> Task, string Name)>();

                foreach (var businessService in _businessServices)
                {
                    listOfTasks.Add((businessService.GetStatusAsync(), businessService.ServiceName));
                }

                //await Task.WhenAll(listOfTasks);

                foreach (var task in listOfTasks)
                {
                    var result = await task.Task;
                    var log    = new StatusLog()
                    {
                        ServiceName = task.Name,
                        Status      = result.StatusCode,
                        Date        = result.Headers.Date ?? DateTimeOffset.Now
                    };
                    _storeService.AddStatusLog(log);
                }
                await _storeService.SaveChangesAsync();

                await Task.Delay(_delay, stoppingToken);
            }
        }