mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 05:53:33 -07:00
Scheduled Tasks should work as long as they are registered.
This commit is contained in:
parent
fa8f67d7fe
commit
32431540c5
21 changed files with 253 additions and 106 deletions
51
NzbDrone.Core/Jobs/Scheduler.cs
Normal file
51
NzbDrone.Core/Jobs/Scheduler.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Timers;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
|
||||
namespace NzbDrone.Core.Jobs
|
||||
{
|
||||
[Singleton]
|
||||
public class Scheduler :
|
||||
IHandle<ApplicationStartedEvent>,
|
||||
IHandle<ApplicationShutdownRequested>
|
||||
{
|
||||
private readonly ITaskManager _taskManager;
|
||||
private readonly IMessageAggregator _messageAggregator;
|
||||
private static readonly Timer Timer = new Timer();
|
||||
|
||||
public Scheduler(ITaskManager taskManager, IMessageAggregator messageAggregator)
|
||||
{
|
||||
_taskManager = taskManager;
|
||||
_messageAggregator = messageAggregator;
|
||||
}
|
||||
|
||||
public void Handle(ApplicationStartedEvent message)
|
||||
{
|
||||
Timer.Interval = 1000 * 30;
|
||||
Timer.Elapsed += (o, args) => ExecuteCommands();
|
||||
Timer.Start();
|
||||
}
|
||||
|
||||
private void ExecuteCommands()
|
||||
{
|
||||
var tasks = _taskManager.GetPending();
|
||||
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
var commandType = Type.GetType(task.Name);
|
||||
var command = (ICommand)Activator.CreateInstance(commandType);
|
||||
|
||||
_messageAggregator.PublishCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(ApplicationShutdownRequested message)
|
||||
{
|
||||
Timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue