From 312672a05c03ccf4dcdf94d8102aef0ebfde0206 Mon Sep 17 00:00:00 2001 From: glax Date: Fri, 19 May 2023 19:20:06 +0200 Subject: [PATCH] Check if task is already being executed before running again. --- Tranga/TaskExecutor.cs | 6 ++++++ Tranga/TrangaTask.cs | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Tranga/TaskExecutor.cs b/Tranga/TaskExecutor.cs index 9b26e28..deb5666 100644 --- a/Tranga/TaskExecutor.cs +++ b/Tranga/TaskExecutor.cs @@ -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> chapterCollection) diff --git a/Tranga/TrangaTask.cs b/Tranga/TrangaTask.cs index fe9af96..946068f 100644 --- a/Tranga/TrangaTask.cs +++ b/Tranga/TrangaTask.cs @@ -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 = "") {