Check if task is already being executed before running again.

This commit is contained in:
glax 2023-05-19 19:20:06 +02:00
parent d659a26987
commit 312672a05c
2 changed files with 10 additions and 1 deletions

View File

@ -7,6 +7,10 @@ public static class TaskExecutor
Connector? connector = connectors.FirstOrDefault(c => c.name == trangaTask.connectorName);
if (connector is null)
throw new ArgumentException($"Connector {trangaTask.connectorName} is not a known connector.");
if (trangaTask.isBeingExecuted)
return;
trangaTask.isBeingExecuted = true;
trangaTask.lastExecuted = DateTime.Now;
switch (trangaTask.task)
@ -21,6 +25,8 @@ public static class TaskExecutor
UpdatePublications(connector, chapterCollection);
break;
}
trangaTask.isBeingExecuted = false;
}
private static void UpdatePublications(Connector connector, Dictionary<Publication, List<Chapter>> chapterCollection)

View File

@ -1,4 +1,6 @@
namespace Tranga;
using Newtonsoft.Json;
namespace Tranga;
public class TrangaTask
{
@ -8,6 +10,7 @@ public class TrangaTask
public Task task { get; }
public Publication? publication { get; }
public string language { get; }
[JsonIgnore]public bool isBeingExecuted { get; set; }
public TrangaTask(string connectorName, Task task, Publication? publication, TimeSpan reoccurrence, string language = "")
{