mirror of
https://github.com/Prowlarr/Prowlarr
synced 2026-01-26 09:32:23 +01:00
Fixed: Cleanup TaskManager, add BackupInterval limits
This commit is contained in:
parent
7700014ceb
commit
1608095345
3 changed files with 63 additions and 15 deletions
|
|
@ -9,8 +9,8 @@ public class ScheduledTask : ModelBase
|
|||
public string TypeName { get; set; }
|
||||
public int Interval { get; set; }
|
||||
public DateTime LastExecution { get; set; }
|
||||
public DateTime LastStartTime { get; set; }
|
||||
public CommandPriority Priority { get; set; }
|
||||
public DateTime LastStartTime { get; set; }
|
||||
|
||||
public ScheduledTask()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public ScheduledTaskRepository(IMainDatabase database, IEventAggregator eventAgg
|
|||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public interface ITaskManager
|
|||
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 IConfigService _configService;
|
||||
|
|
@ -63,13 +63,47 @@ public void Handle(ApplicationStartedEvent message)
|
|||
{
|
||||
var defaultTasks = new List<ScheduledTask>
|
||||
{
|
||||
new ScheduledTask { Interval = 5, TypeName = typeof(MessagingCleanupCommand).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
|
||||
{
|
||||
Interval = 5,
|
||||
TypeName = typeof(MessagingCleanupCommand).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
|
||||
{
|
||||
|
|
@ -111,9 +145,19 @@ public void Handle(ApplicationStartedEvent message)
|
|||
|
||||
private int GetBackupInterval()
|
||||
{
|
||||
var interval = _configService.BackupInterval;
|
||||
var intervalMinutes = _configService.BackupInterval;
|
||||
|
||||
return interval * 60 * 24;
|
||||
if (intervalMinutes < 1)
|
||||
{
|
||||
intervalMinutes = 1;
|
||||
}
|
||||
|
||||
if (intervalMinutes > 7)
|
||||
{
|
||||
intervalMinutes = 7;
|
||||
}
|
||||
|
||||
return intervalMinutes * 60 * 24;
|
||||
}
|
||||
|
||||
public void Handle(CommandExecutedEvent message)
|
||||
|
|
@ -125,10 +169,14 @@ public void Handle(CommandExecutedEvent message)
|
|||
_logger.Trace("Updating last run time for: {0}", scheduledTask.TypeName);
|
||||
|
||||
var lastExecution = DateTime.UtcNow;
|
||||
var startTime = message.Command.StartedAt.Value;
|
||||
|
||||
_scheduledTaskRepository.SetLastExecutionTime(scheduledTask.Id, lastExecution, message.Command.StartedAt.Value);
|
||||
_cache.Find(scheduledTask.TypeName).LastExecution = lastExecution;
|
||||
_cache.Find(scheduledTask.TypeName).LastStartTime = message.Command.StartedAt.Value;
|
||||
_scheduledTaskRepository.SetLastExecutionTime(scheduledTask.Id, lastExecution, startTime);
|
||||
|
||||
var cached = _cache.Find(scheduledTask.TypeName);
|
||||
|
||||
cached.LastExecution = lastExecution;
|
||||
cached.LastStartTime = startTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue