using System; using System.Collections.Generic; using System.Linq; using NzbDrone.Core.ThingiProvider.Status; namespace NzbDrone.Core.Housekeeping.Housekeepers { public abstract class FixFutureProviderStatusTimes where TModel : ProviderStatusBase, new() { private readonly IProviderStatusRepository _repo; protected FixFutureProviderStatusTimes(IProviderStatusRepository repo) { _repo = repo; } public void Clean() { var now = DateTime.UtcNow; var statuses = _repo.All().ToList(); var toUpdate = new List(); foreach (var status in statuses) { var updated = false; var escalationDelay = EscalationBackOff.Periods[status.EscalationLevel]; var disabledTill = now.AddMinutes(escalationDelay); if (status.DisabledTill > disabledTill) { status.DisabledTill = disabledTill; updated = true; } if (status.InitialFailure > now) { status.InitialFailure = now; updated = true; } if (status.MostRecentFailure > now) { status.MostRecentFailure = now; updated = true; } if (updated) { toUpdate.Add(status); } } _repo.UpdateMany(toUpdate); } } }