Ejemplo n.º 1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    var currentStatusRecordIds = _statusRepository
                                                 .GetLatestStatusRecordForEachLocation()
                                                 .Select(sr => sr.Id)
                                                 .ToList();

                    var oldRecords = await _statusRepository.GetStatusMonitorRepliesOlderThan(DateTime.Now.AddDays(-14));

                    var recordsToDelete = oldRecords.Where(sr => currentStatusRecordIds.All(id => sr.Id != id)).ToList();
                    await _statusRepository.DeleteStatusRecords(recordsToDelete);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.Message);
                }
                finally
                {
                    await Task.Delay(1000 * 60 * 15, stoppingToken); // 15 minutes
                }
            }
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    var datedStatusRecords = _statusRepository
                                             .GetLatestStatusRecordForEachLocation()
                                             .Where(x => x.LastStatusUpdateTime < DateTime.Now.AddHours(-2))
                                             .ToList();

                    foreach (var datedStatusRecord in datedStatusRecords)
                    {
                        if (datedStatusRecord.Status != Offline)
                        {
                            _statusRepository.AddStatusRecord(new StatusMonitorReply
                            {
                                Status               = Offline,
                                MonitorName          = datedStatusRecord.MonitorName,
                                DisplayName          = datedStatusRecord.DisplayName,
                                LocationId           = datedStatusRecord.LocationId,
                                LastStatusUpdateTime = DateTime.Now,
                                StatusStartTime      = DateTime.Now
                            });
                        }

                        _statusRepository.Update(datedStatusRecord.LocationId, datedStatusRecord.MonitorName, datedStatusRecord.DisplayName, DateTime.Now);
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.Message);
                }
                finally
                {
                    await Task.Delay(1000 * 60 * 15, stoppingToken); // 15 minutes
                }
            }
        }
 public void OnGet()
 {
     StatusReplies = _statusReplies.GetLatestStatusRecordForEachLocation().Where(x => x.MonitorName == MonitorName);
 }
Ejemplo n.º 4
0
 public void OnGet()
 {
     StatusReplies = _statusReplies.GetLatestStatusRecordForEachLocation();
 }