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);
|
Connector? connector = connectors.FirstOrDefault(c => c.name == trangaTask.connectorName);
|
||||||
if (connector is null)
|
if (connector is null)
|
||||||
throw new ArgumentException($"Connector {trangaTask.connectorName} is not a known connector.");
|
throw new ArgumentException($"Connector {trangaTask.connectorName} is not a known connector.");
|
||||||
|
|
||||||
|
if (trangaTask.isBeingExecuted)
|
||||||
|
return;
|
||||||
|
trangaTask.isBeingExecuted = true;
|
||||||
trangaTask.lastExecuted = DateTime.Now;
|
trangaTask.lastExecuted = DateTime.Now;
|
||||||
|
|
||||||
switch (trangaTask.task)
|
switch (trangaTask.task)
|
||||||
@ -21,6 +25,8 @@ public static class TaskExecutor
|
|||||||
UpdatePublications(connector, chapterCollection);
|
UpdatePublications(connector, chapterCollection);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trangaTask.isBeingExecuted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdatePublications(Connector connector, Dictionary<Publication, List<Chapter>> chapterCollection)
|
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
|
public class TrangaTask
|
||||||
{
|
{
|
||||||
@ -8,6 +10,7 @@ public class TrangaTask
|
|||||||
public Task task { get; }
|
public Task task { get; }
|
||||||
public Publication? publication { get; }
|
public Publication? publication { get; }
|
||||||
public string language { get; }
|
public string language { get; }
|
||||||
|
[JsonIgnore]public bool isBeingExecuted { get; set; }
|
||||||
|
|
||||||
public TrangaTask(string connectorName, Task task, Publication? publication, TimeSpan reoccurrence, string language = "")
|
public TrangaTask(string connectorName, Task task, Publication? publication, TimeSpan reoccurrence, string language = "")
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user