mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
Command queue
New: Adding multiple series will queue them instead of running all at once New: Slower scheduled tasks won't be block others from running
This commit is contained in:
@@ -1,20 +1,9 @@
|
||||
using System;
|
||||
using FluentMigrator.Runner;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Commands.Tracking;
|
||||
|
||||
namespace NzbDrone.Core.Messaging.Commands
|
||||
{
|
||||
public abstract class Command : ModelBase, IMessage
|
||||
public abstract class Command
|
||||
{
|
||||
private static readonly object Mutex = new object();
|
||||
private static int _idCounter;
|
||||
private readonly StopWatch _stopWatch;
|
||||
|
||||
public CommandStatus State { get; private set; }
|
||||
public DateTime StateChangeTime { get; private set; }
|
||||
|
||||
public virtual Boolean SendUpdatesToClient
|
||||
{
|
||||
get
|
||||
@@ -23,63 +12,21 @@ namespace NzbDrone.Core.Messaging.Commands
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan Runtime
|
||||
public virtual string CompletionMessage
|
||||
{
|
||||
get
|
||||
{
|
||||
return _stopWatch.ElapsedTime();
|
||||
return "Completed";
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean Manual { get; set; }
|
||||
public Exception Exception { get; private set; }
|
||||
public String Message { get; private set; }
|
||||
|
||||
public String Name { get; private set; }
|
||||
public DateTime? LastExecutionTime { get; set; }
|
||||
public CommandTrigger Trigger { get; set; }
|
||||
|
||||
protected Command()
|
||||
public Command()
|
||||
{
|
||||
Name = GetType().Name.Replace("Command", "");
|
||||
StateChangeTime = DateTime.UtcNow;
|
||||
State = CommandStatus.Pending;
|
||||
_stopWatch = new StopWatch();
|
||||
Manual = false;
|
||||
|
||||
lock (Mutex)
|
||||
{
|
||||
Id = ++_idCounter;
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_stopWatch.Start();
|
||||
StateChangeTime = DateTime.UtcNow;
|
||||
State = CommandStatus.Running;
|
||||
SetMessage("Starting");
|
||||
}
|
||||
|
||||
public void Failed(Exception exception, string message = "Failed")
|
||||
{
|
||||
_stopWatch.Stop();
|
||||
StateChangeTime = DateTime.UtcNow;
|
||||
State = CommandStatus.Failed;
|
||||
Exception = exception;
|
||||
SetMessage(message);
|
||||
}
|
||||
|
||||
public void Completed(string message = "Completed")
|
||||
{
|
||||
_stopWatch.Stop();
|
||||
StateChangeTime = DateTime.UtcNow;
|
||||
State = CommandStatus.Completed;
|
||||
SetMessage(message);
|
||||
}
|
||||
|
||||
public void SetMessage(string message)
|
||||
{
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user