2
0

Cancel Running Jobs if inactive for more than 5 minutes

This commit is contained in:
glax 2023-10-03 20:46:21 +02:00
parent 73492d8102
commit 95fcc73c74
2 changed files with 11 additions and 1 deletions

View File

@ -238,6 +238,9 @@ public class JobBoss : GlobalBase
Job[] subJobs = jobQueue.Peek().ExecuteReturnSubTasks().ToArray(); Job[] subJobs = jobQueue.Peek().ExecuteReturnSubTasks().ToArray();
AddJobs(subJobs); AddJobs(subJobs);
AddJobsToQueue(subJobs); AddJobsToQueue(subJobs);
}else if (queueHead.progressToken.state is ProgressToken.State.Running && DateTime.Now.Subtract(queueHead.progressToken.lastUpdate) > TimeSpan.FromMinutes(5))
{
queueHead.Cancel();
} }
} }
} }

View File

@ -6,7 +6,7 @@ public class ProgressToken
public int increments { get; set; } public int increments { get; set; }
public int incrementsCompleted { get; set; } public int incrementsCompleted { get; set; }
public float progress => GetProgress(); public float progress => GetProgress();
public DateTime lastUpdate { get; private set; }
public DateTime executionStarted { get; private set; } public DateTime executionStarted { get; private set; }
public TimeSpan timeRemaining => GetTimeRemaining(); public TimeSpan timeRemaining => GetTimeRemaining();
@ -20,6 +20,7 @@ public class ProgressToken
this.incrementsCompleted = 0; this.incrementsCompleted = 0;
this.state = State.Waiting; this.state = State.Waiting;
this.executionStarted = DateTime.UnixEpoch; this.executionStarted = DateTime.UnixEpoch;
this.lastUpdate = DateTime.UnixEpoch;
} }
private float GetProgress() private float GetProgress()
@ -38,6 +39,7 @@ public class ProgressToken
public void Increment() public void Increment()
{ {
this.lastUpdate = DateTime.Now;
this.incrementsCompleted++; this.incrementsCompleted++;
if (incrementsCompleted > increments) if (incrementsCompleted > increments)
state = State.Complete; state = State.Complete;
@ -45,27 +47,32 @@ public class ProgressToken
public void Standby() public void Standby()
{ {
this.lastUpdate = DateTime.Now;
state = State.Standby; state = State.Standby;
} }
public void Start() public void Start()
{ {
this.lastUpdate = DateTime.Now;
state = State.Running; state = State.Running;
this.executionStarted = DateTime.Now; this.executionStarted = DateTime.Now;
} }
public void Complete() public void Complete()
{ {
this.lastUpdate = DateTime.Now;
state = State.Complete; state = State.Complete;
} }
public void Cancel() public void Cancel()
{ {
this.lastUpdate = DateTime.Now;
state = State.Cancelled; state = State.Cancelled;
} }
public void Waiting() public void Waiting()
{ {
this.lastUpdate = DateTime.Now;
state = State.Waiting; state = State.Waiting;
} }
} }