Fixed: Cleanup TaskManager, add BackupInterval limits

pull/1597/head
Qstick 2 years ago
parent 7700014ceb
commit 1608095345

@ -9,8 +9,8 @@ namespace NzbDrone.Core.Jobs
public string TypeName { get; set; } public string TypeName { get; set; }
public int Interval { get; set; } public int Interval { get; set; }
public DateTime LastExecution { get; set; } public DateTime LastExecution { get; set; }
public DateTime LastStartTime { get; set; }
public CommandPriority Priority { get; set; } public CommandPriority Priority { get; set; }
public DateTime LastStartTime { get; set; }
public ScheduledTask() public ScheduledTask()
{ {

@ -20,7 +20,7 @@ namespace NzbDrone.Core.Jobs
public ScheduledTask GetDefinition(Type type) public ScheduledTask GetDefinition(Type type)
{ {
return Query(x => x.TypeName == type.FullName).Single(); return Query(c => c.TypeName == type.FullName).Single();
} }
public void SetLastExecutionTime(int id, DateTime executionTime, DateTime startTime) public void SetLastExecutionTime(int id, DateTime executionTime, DateTime startTime)

@ -25,7 +25,7 @@ namespace NzbDrone.Core.Jobs
DateTime GetNextExecution(Type type); DateTime GetNextExecution(Type type);
} }
public class TaskManager : ITaskManager, IHandle<ApplicationStartedEvent>, IHandle<CommandExecutedEvent> public class TaskManager : ITaskManager, IHandle<ApplicationStartedEvent>, IHandle<CommandExecutedEvent>, IHandleAsync<ConfigSavedEvent>
{ {
private readonly IScheduledTaskRepository _scheduledTaskRepository; private readonly IScheduledTaskRepository _scheduledTaskRepository;
private readonly IConfigService _configService; private readonly IConfigService _configService;
@ -63,13 +63,47 @@ namespace NzbDrone.Core.Jobs
{ {
var defaultTasks = new List<ScheduledTask> var defaultTasks = new List<ScheduledTask>
{ {
new ScheduledTask { Interval = 5, TypeName = typeof(MessagingCleanupCommand).FullName }, new ScheduledTask
new ScheduledTask { Interval = 6 * 60, TypeName = typeof(ApplicationCheckUpdateCommand).FullName }, {
new ScheduledTask { Interval = 6 * 60, TypeName = typeof(CheckHealthCommand).FullName }, Interval = 5,
new ScheduledTask { Interval = 24 * 60, TypeName = typeof(HousekeepingCommand).FullName }, TypeName = typeof(MessagingCleanupCommand).FullName
new ScheduledTask { Interval = 24 * 60, TypeName = typeof(CleanUpHistoryCommand).FullName }, },
new ScheduledTask { Interval = 24 * 60, TypeName = typeof(IndexerDefinitionUpdateCommand).FullName },
new ScheduledTask { Interval = 6 * 60, TypeName = typeof(ApplicationIndexerSyncCommand).FullName }, new ScheduledTask
{
Interval = 6 * 60,
TypeName = typeof(ApplicationCheckUpdateCommand).FullName
},
new ScheduledTask
{
Interval = 6 * 60,
TypeName = typeof(CheckHealthCommand).FullName
},
new ScheduledTask
{
Interval = 24 * 60,
TypeName = typeof(HousekeepingCommand).FullName
},
new ScheduledTask
{
Interval = 24 * 60,
TypeName = typeof(CleanUpHistoryCommand).FullName
},
new ScheduledTask
{
Interval = 24 * 60,
TypeName = typeof(IndexerDefinitionUpdateCommand).FullName
},
new ScheduledTask
{
Interval = 6 * 60,
TypeName = typeof(ApplicationIndexerSyncCommand).FullName
},
new ScheduledTask new ScheduledTask
{ {
@ -111,9 +145,19 @@ namespace NzbDrone.Core.Jobs
private int GetBackupInterval() private int GetBackupInterval()
{ {
var interval = _configService.BackupInterval; var intervalMinutes = _configService.BackupInterval;
if (intervalMinutes < 1)
{
intervalMinutes = 1;
}
return interval * 60 * 24; if (intervalMinutes > 7)
{
intervalMinutes = 7;
}
return intervalMinutes * 60 * 24;
} }
public void Handle(CommandExecutedEvent message) public void Handle(CommandExecutedEvent message)
@ -125,10 +169,14 @@ namespace NzbDrone.Core.Jobs
_logger.Trace("Updating last run time for: {0}", scheduledTask.TypeName); _logger.Trace("Updating last run time for: {0}", scheduledTask.TypeName);
var lastExecution = DateTime.UtcNow; var lastExecution = DateTime.UtcNow;
var startTime = message.Command.StartedAt.Value;
_scheduledTaskRepository.SetLastExecutionTime(scheduledTask.Id, lastExecution, startTime);
var cached = _cache.Find(scheduledTask.TypeName);
_scheduledTaskRepository.SetLastExecutionTime(scheduledTask.Id, lastExecution, message.Command.StartedAt.Value); cached.LastExecution = lastExecution;
_cache.Find(scheduledTask.TypeName).LastExecution = lastExecution; cached.LastStartTime = startTime;
_cache.Find(scheduledTask.TypeName).LastStartTime = message.Command.StartedAt.Value;
} }
} }

Loading…
Cancel
Save