Implemented Queue, so that taskManager is not held up with other Connector-tasks.

Tasks are now executed in another Thread.
Replaced TrangaTask.isBeingExecuted bool with 3-states: Waiting, Enqueued, Running
Added Queue size to CLI output.
This commit is contained in:
2023-05-20 14:50:48 +02:00
parent 58de0115d6
commit 430ee2301f
4 changed files with 47 additions and 20 deletions

View File

@ -16,15 +16,14 @@ public static class TaskExecutor
/// <exception cref="ArgumentException">Is thrown when there is no Connector available with the name of the TrangaTask.connectorName</exception>
public static void Execute(TaskManager taskManager, TrangaTask trangaTask, Dictionary<Publication, List<Chapter>> chapterCollection)
{
if (trangaTask.state == TrangaTask.ExecutionState.Running)
return;
trangaTask.state = TrangaTask.ExecutionState.Running;
Connector? connector = null;
if (trangaTask.task != TrangaTask.Task.UpdateKomgaLibrary)
connector = taskManager.GetConnector(trangaTask.connectorName!);
if (trangaTask.isBeingExecuted)
return;
trangaTask.isBeingExecuted = true;
trangaTask.lastExecuted = DateTime.Now;
//Call appropriate Method based on TrangaTask.Task
switch (trangaTask.task)
{
@ -42,7 +41,8 @@ public static class TaskExecutor
break;
}
trangaTask.isBeingExecuted = false;
trangaTask.state = TrangaTask.ExecutionState.Waiting;
trangaTask.lastExecuted = DateTime.Now;
}
/// <summary>