removed all the jobs.

This commit is contained in:
Keivan Beigi
2013-05-06 17:39:33 -07:00
parent 40f384968a
commit ec58b8b595
42 changed files with 122 additions and 1599 deletions

View File

@@ -1,4 +1,5 @@
using System.Timers;
using System;
using System.Timers;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Lifecycle;
@@ -8,23 +9,37 @@ namespace NzbDrone.Core.Jobs
IHandle<ApplicationStartedEvent>,
IHandle<ApplicationShutdownRequested>
{
private readonly IJobController _jobController;
private readonly IJobRepository _jobRepository;
private readonly IMessageAggregator _messageAggregator;
private readonly Timer _timer;
public JobTimer(IJobController jobController)
public JobTimer(IJobRepository jobRepository, IMessageAggregator messageAggregator)
{
_jobController = jobController;
_jobRepository = jobRepository;
_messageAggregator = messageAggregator;
_timer = new Timer();
}
public void Handle(ApplicationStartedEvent message)
{
_timer.Interval = 1000 * 30;
_timer.Elapsed += (o, args) => _jobController.EnqueueScheduled();
_timer.Elapsed += (o, args) => ExecuteCommands();
_timer.Start();
}
private void ExecuteCommands()
{
var jobs = _jobRepository.GetPendingJobs();
foreach (var jobDefinition in jobs)
{
var commandType = Type.GetType(jobDefinition.Name);
var command = (ICommand)Activator.CreateInstance(commandType);
_messageAggregator.PublishCommand(command);
}
}
public void Handle(ApplicationShutdownRequested message)
{
_timer.Stop();