From 95fcc73c7437e96786fe8755ec53d4d8e4efcf9b Mon Sep 17 00:00:00 2001 From: glax Date: Tue, 3 Oct 2023 20:46:21 +0200 Subject: [PATCH] Cancel Running Jobs if inactive for more than 5 minutes --- Tranga/Jobs/JobBoss.cs | 3 +++ Tranga/Jobs/ProgressToken.cs | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 7be8a0c..cf87212 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -238,6 +238,9 @@ public class JobBoss : GlobalBase Job[] subJobs = jobQueue.Peek().ExecuteReturnSubTasks().ToArray(); AddJobs(subJobs); AddJobsToQueue(subJobs); + }else if (queueHead.progressToken.state is ProgressToken.State.Running && DateTime.Now.Subtract(queueHead.progressToken.lastUpdate) > TimeSpan.FromMinutes(5)) + { + queueHead.Cancel(); } } } diff --git a/Tranga/Jobs/ProgressToken.cs b/Tranga/Jobs/ProgressToken.cs index f23819d..b6b4167 100644 --- a/Tranga/Jobs/ProgressToken.cs +++ b/Tranga/Jobs/ProgressToken.cs @@ -6,7 +6,7 @@ public class ProgressToken public int increments { get; set; } public int incrementsCompleted { get; set; } public float progress => GetProgress(); - + public DateTime lastUpdate { get; private set; } public DateTime executionStarted { get; private set; } public TimeSpan timeRemaining => GetTimeRemaining(); @@ -20,6 +20,7 @@ public class ProgressToken this.incrementsCompleted = 0; this.state = State.Waiting; this.executionStarted = DateTime.UnixEpoch; + this.lastUpdate = DateTime.UnixEpoch; } private float GetProgress() @@ -38,6 +39,7 @@ public class ProgressToken public void Increment() { + this.lastUpdate = DateTime.Now; this.incrementsCompleted++; if (incrementsCompleted > increments) state = State.Complete; @@ -45,27 +47,32 @@ public class ProgressToken public void Standby() { + this.lastUpdate = DateTime.Now; state = State.Standby; } public void Start() { + this.lastUpdate = DateTime.Now; state = State.Running; this.executionStarted = DateTime.Now; } public void Complete() { + this.lastUpdate = DateTime.Now; state = State.Complete; } public void Cancel() { + this.lastUpdate = DateTime.Now; state = State.Cancelled; } public void Waiting() { + this.lastUpdate = DateTime.Now; state = State.Waiting; } } \ No newline at end of file