|
|
@ -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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|