Added an overloaded AddTask method that allows tasks to skip the queue and updated the api call backup/<id>/run to skip the queue to correspond with the expectation of the 'Run now' button in the UI

This commit is contained in:
Pectojin
2018-02-03 04:17:10 +01:00
parent e65d38e235
commit f6242e3774
2 changed files with 35 additions and 1 deletions
+34
View File
@@ -162,6 +162,40 @@ namespace Duplicati.Library.Utility
WorkQueueChanged(this);
}
/// <summary>
/// An overloaded AddTask method that allows a task to skip to the front of a queue
/// It does this by creating a new queue, adding the new task first, and then adding
/// all the old tasks to the new queue. It's cleaner to use a linked list,
/// but the performance difference is negligible on such a small queue.
/// </summary>
/// <param name="task">Task.</param>
/// <param name="skipQueue">If set to <c>true</c> skip queue.</param>
public void AddTask(Tx task, bool skipQueue)
{
if (!skipQueue) {
// Fall back to default AddTask method
AddTask(task);
return;
}
lock (m_lock)
{
Queue<Tx> newQueue = new Queue<Tx>();
newQueue.Enqueue(task);
while (m_tasks.Count > 0)
{
Tx n = m_tasks.Dequeue();
newQueue.Enqueue(n);
}
m_tasks = newQueue;
m_event.Set();
}
if (WorkQueueChanged != null)
WorkQueueChanged(this);
}
/// <summary>
/// Removes a task from the queue, does not remove the task if it is currently running
/// </summary>
@@ -293,7 +293,7 @@ namespace Duplicati.Server.WebServer.RESTMethods
}
else
{
Program.WorkThread.AddTask(Runner.CreateTask(DuplicatiOperation.Backup, backup));
Program.WorkThread.AddTask(Runner.CreateTask(DuplicatiOperation.Backup, backup), true);
Program.StatusEventNotifyer.SignalNewEvent();
}