diff --git a/Tranga/Jobs/Job.cs b/Tranga/Jobs/Job.cs index f76253c..0f0fc5d 100644 --- a/Tranga/Jobs/Job.cs +++ b/Tranga/Jobs/Job.cs @@ -61,12 +61,12 @@ public abstract class Job : GlobalBase { this.progressToken.increments -= progressToken.incrementsCompleted; this.lastExecution = DateTime.Now; + this.progressToken.Waiting(); } public void ExecutionEnqueue() { this.progressToken.increments -= progressToken.incrementsCompleted; - this.lastExecution = recurrenceTime is not null ? DateTime.Now.Subtract((TimeSpan)recurrenceTime) : DateTime.UnixEpoch; this.progressToken.Standby(); } diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 8ddf01d..7be8a0c 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -220,8 +220,7 @@ public class JobBoss : GlobalBase public void CheckJobs() { - foreach (Job job in jobs.Where(job => job.nextExecution < DateTime.Now && !QueueContainsJob(job)).OrderBy(job => job.nextExecution)) - AddJobToQueue(job); + AddJobsToQueue(jobs.Where(job => job.progressToken.state == ProgressToken.State.Waiting && job.nextExecution < DateTime.Now && !QueueContainsJob(job)).OrderBy(job => job.nextExecution)); foreach (Queue jobQueue in mangaConnectorJobQueue.Values) { if(jobQueue.Count < 1) @@ -229,19 +228,10 @@ public class JobBoss : GlobalBase Job queueHead = jobQueue.Peek(); 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(); + if(!queueHead.recurring) + RemoveJob(queueHead); jobQueue.Dequeue(); - ExportJob(queueHead); 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) { diff --git a/Tranga/Jobs/ProgressToken.cs b/Tranga/Jobs/ProgressToken.cs index 9bada05..f23819d 100644 --- a/Tranga/Jobs/ProgressToken.cs +++ b/Tranga/Jobs/ProgressToken.cs @@ -10,7 +10,7 @@ public class ProgressToken public DateTime executionStarted { get; private set; } 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 ProgressToken(int increments) @@ -18,7 +18,7 @@ public class ProgressToken this.cancellationRequested = false; this.increments = increments; this.incrementsCompleted = 0; - this.state = State.Complete; + this.state = State.Waiting; this.executionStarted = DateTime.UnixEpoch; } @@ -63,4 +63,9 @@ public class ProgressToken { state = State.Cancelled; } + + public void Waiting() + { + state = State.Waiting; + } } \ No newline at end of file diff --git a/Tranga/Tranga.cs b/Tranga/Tranga.cs index 86ffc1e..23846b8 100644 --- a/Tranga/Tranga.cs +++ b/Tranga/Tranga.cs @@ -72,11 +72,6 @@ public partial class Tranga : GlobalBase jobBoss.CheckJobs(); Thread.Sleep(100); } - - foreach (MangaConnector connector in _connectors) - { - - } }); t.Start(); }