Check if task is already being executed before running again.
This commit is contained in:
parent
d659a26987
commit
312672a05c
@ -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)
|
||||
|
@ -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 = "")
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user