2
0

Added ProgressToken state Cancelled

This commit is contained in:
glax 2023-09-02 14:45:46 +02:00
parent 37cf47bc17
commit 0b77dc1172
3 changed files with 23 additions and 2 deletions

View File

@ -59,13 +59,15 @@ public abstract class Job : GlobalBase
public void ResetProgress() public void ResetProgress()
{ {
this.progressToken = new ProgressToken(this.progressToken.increments); this.progressToken = new ProgressToken(this.progressToken.increments);
this.lastExecution = DateTime.Now;
} }
public void Cancel() public void Cancel()
{ {
Log($"Cancelling {this}"); Log($"Cancelling {this}");
this.progressToken.cancellationRequested = true; this.progressToken.cancellationRequested = true;
this.progressToken.Complete(); this.progressToken.Cancel();
this.lastExecution = DateTime.Now;
if(subJobs is not null) if(subJobs is not null)
foreach(Job subJob in subJobs) foreach(Job subJob in subJobs)
subJob.Cancel(); subJob.Cancel();

View File

@ -146,6 +146,20 @@ public class JobBoss : GlobalBase
jobQueue.Dequeue(); jobQueue.Dequeue();
}else if(queueHead.progressToken.state is ProgressToken.State.Standby) }else if(queueHead.progressToken.state is ProgressToken.State.Standby)
AddJobsToQueue(jobQueue.Peek().ExecuteReturnSubTasks()); AddJobsToQueue(jobQueue.Peek().ExecuteReturnSubTasks());
else if (queueHead.progressToken.state is ProgressToken.State.Cancelled)
{
switch (queueHead)
{
case DownloadChapter:
RemoveJob(queueHead);
break;
case DownloadNewChapters:
if(queueHead.recurring)
queueHead.progressToken.Complete();
break;
}
jobQueue.Dequeue();
}
} }
} }
} }

View File

@ -7,7 +7,7 @@ public class ProgressToken
public int incrementsCompleted { get; set; } public int incrementsCompleted { get; set; }
public float progress => GetProgress(); public float progress => GetProgress();
public enum State { Running, Complete, Standby } public enum State { Running, Complete, Standby, Cancelled }
public State state { get; private set; } public State state { get; private set; }
public ProgressToken(int increments) public ProgressToken(int increments)
@ -41,4 +41,9 @@ public class ProgressToken
{ {
state = State.Complete; state = State.Complete;
} }
public void Cancel()
{
state = State.Cancelled;
}
} }