Changed (fixed?) queuelogic

This commit is contained in:
glax 2023-09-20 21:59:39 +02:00
parent 306cb87d67
commit 3c2ce266f6
4 changed files with 11 additions and 21 deletions

View File

@ -61,12 +61,12 @@ public abstract class Job : GlobalBase
{ {
this.progressToken.increments -= progressToken.incrementsCompleted; this.progressToken.increments -= progressToken.incrementsCompleted;
this.lastExecution = DateTime.Now; this.lastExecution = DateTime.Now;
this.progressToken.Waiting();
} }
public void ExecutionEnqueue() public void ExecutionEnqueue()
{ {
this.progressToken.increments -= progressToken.incrementsCompleted; this.progressToken.increments -= progressToken.incrementsCompleted;
this.lastExecution = recurrenceTime is not null ? DateTime.Now.Subtract((TimeSpan)recurrenceTime) : DateTime.UnixEpoch;
this.progressToken.Standby(); this.progressToken.Standby();
} }

View File

@ -220,8 +220,7 @@ public class JobBoss : GlobalBase
public void CheckJobs() public void CheckJobs()
{ {
foreach (Job job in jobs.Where(job => job.nextExecution < DateTime.Now && !QueueContainsJob(job)).OrderBy(job => job.nextExecution)) AddJobsToQueue(jobs.Where(job => job.progressToken.state == ProgressToken.State.Waiting && job.nextExecution < DateTime.Now && !QueueContainsJob(job)).OrderBy(job => job.nextExecution));
AddJobToQueue(job);
foreach (Queue<Job> jobQueue in mangaConnectorJobQueue.Values) foreach (Queue<Job> jobQueue in mangaConnectorJobQueue.Values)
{ {
if(jobQueue.Count < 1) if(jobQueue.Count < 1)
@ -229,19 +228,10 @@ public class JobBoss : GlobalBase
Job queueHead = jobQueue.Peek(); Job queueHead = jobQueue.Peek();
if (queueHead.progressToken.state is ProgressToken.State.Complete or ProgressToken.State.Cancelled) if (queueHead.progressToken.state is ProgressToken.State.Complete or ProgressToken.State.Cancelled)
{ {
switch (queueHead)
{
case DownloadChapter:
RemoveJob(queueHead);
break;
case DownloadNewChapters:
if(queueHead.recurring)
queueHead.progressToken.Complete();
break;
}
queueHead.ResetProgress(); queueHead.ResetProgress();
if(!queueHead.recurring)
RemoveJob(queueHead);
jobQueue.Dequeue(); jobQueue.Dequeue();
ExportJob(queueHead);
Log($"Next job in {jobs.MinBy(job => job.nextExecution)?.nextExecution.Subtract(DateTime.Now)} {jobs.MinBy(job => job.nextExecution)?.id}"); Log($"Next job in {jobs.MinBy(job => job.nextExecution)?.nextExecution.Subtract(DateTime.Now)} {jobs.MinBy(job => job.nextExecution)?.id}");
}else if (queueHead.progressToken.state is ProgressToken.State.Standby) }else if (queueHead.progressToken.state is ProgressToken.State.Standby)
{ {

View File

@ -10,7 +10,7 @@ public class ProgressToken
public DateTime executionStarted { get; private set; } public DateTime executionStarted { get; private set; }
public TimeSpan timeRemaining => GetTimeRemaining(); public TimeSpan timeRemaining => GetTimeRemaining();
public enum State { Running, Complete, Standby, Cancelled } public enum State { Running, Complete, Standby, Cancelled, Waiting }
public State state { get; private set; } public State state { get; private set; }
public ProgressToken(int increments) public ProgressToken(int increments)
@ -18,7 +18,7 @@ public class ProgressToken
this.cancellationRequested = false; this.cancellationRequested = false;
this.increments = increments; this.increments = increments;
this.incrementsCompleted = 0; this.incrementsCompleted = 0;
this.state = State.Complete; this.state = State.Waiting;
this.executionStarted = DateTime.UnixEpoch; this.executionStarted = DateTime.UnixEpoch;
} }
@ -63,4 +63,9 @@ public class ProgressToken
{ {
state = State.Cancelled; state = State.Cancelled;
} }
public void Waiting()
{
state = State.Waiting;
}
} }

View File

@ -72,11 +72,6 @@ public partial class Tranga : GlobalBase
jobBoss.CheckJobs(); jobBoss.CheckJobs();
Thread.Sleep(100); Thread.Sleep(100);
} }
foreach (MangaConnector connector in _connectors)
{
}
}); });
t.Start(); t.Start();
} }