Added lastExecution time on jobs.json parse
This commit is contained in:
parent
ae5be31c89
commit
79bbc92467
@ -7,6 +7,13 @@ public class DownloadNewChapters : Job
|
||||
{
|
||||
public Manga manga { get; init; }
|
||||
|
||||
public DownloadNewChapters(GlobalBase clone, MangaConnector connector, Manga manga, DateTime lastExecution,
|
||||
bool recurring = false, TimeSpan? recurrence = null) : base(clone, connector, lastExecution, recurring,
|
||||
recurrence)
|
||||
{
|
||||
this.manga = manga;
|
||||
}
|
||||
|
||||
public DownloadNewChapters(GlobalBase clone, MangaConnector connector, Manga manga, bool recurring = false, TimeSpan? recurrence = null) : base (clone, connector, recurring, recurrence)
|
||||
{
|
||||
this.manga = manga;
|
||||
|
@ -13,7 +13,7 @@ public abstract class Job : GlobalBase
|
||||
public string id => GetId();
|
||||
internal IEnumerable<Job>? subJobs { get; private set; }
|
||||
|
||||
public Job(GlobalBase clone, MangaConnector connector, bool recurring = false, TimeSpan? recurrenceTime = null) : base(clone)
|
||||
internal Job(GlobalBase clone, MangaConnector connector, bool recurring = false, TimeSpan? recurrenceTime = null) : base(clone)
|
||||
{
|
||||
this.mangaConnector = connector;
|
||||
this.progressToken = new ProgressToken(0);
|
||||
@ -25,6 +25,19 @@ public abstract class Job : GlobalBase
|
||||
this.recurrenceTime = recurrenceTime;
|
||||
}
|
||||
|
||||
internal Job(GlobalBase clone, MangaConnector connector, DateTime lastExecution, bool recurring = false,
|
||||
TimeSpan? recurrenceTime = null) : base(clone)
|
||||
{
|
||||
this.mangaConnector = connector;
|
||||
this.progressToken = new ProgressToken(0);
|
||||
this.recurring = recurring;
|
||||
if (recurring && recurrenceTime is null)
|
||||
throw new ArgumentException("If recurrence is set to true, a recurrence time has to be provided.");
|
||||
this.lastExecution = lastExecution;
|
||||
this.recurrenceTime = recurrenceTime;
|
||||
|
||||
}
|
||||
|
||||
protected abstract string GetId();
|
||||
|
||||
public Job(GlobalBase clone, MangaConnector connector, ProgressToken progressToken, bool recurring = false, TimeSpan? recurrenceTime = null) : base(clone)
|
||||
|
@ -29,9 +29,7 @@ public class JobBoss : GlobalBase
|
||||
{
|
||||
Log($"Added {job}");
|
||||
this.jobs.Add(job);
|
||||
while(IsFileInUse(settings.jobsFilePath))
|
||||
Thread.Sleep(10);
|
||||
File.WriteAllText(settings.jobsFilePath, JsonConvert.SerializeObject(this.jobs));
|
||||
ExportJobsList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,9 +53,7 @@ public class JobBoss : GlobalBase
|
||||
this.jobs.Remove(job);
|
||||
if(job.subJobs is not null)
|
||||
RemoveJobs(job.subJobs);
|
||||
while(IsFileInUse(settings.jobsFilePath))
|
||||
Thread.Sleep(10);
|
||||
File.WriteAllText(settings.jobsFilePath, JsonConvert.SerializeObject(this.jobs));
|
||||
ExportJobsList();
|
||||
}
|
||||
|
||||
public void RemoveJobs(IEnumerable<Job?> jobsToRemove)
|
||||
@ -139,6 +135,14 @@ public class JobBoss : GlobalBase
|
||||
AddJobToQueue(job);
|
||||
}
|
||||
|
||||
public void ExportJobsList()
|
||||
{
|
||||
Log($"Exporting {settings.jobsFilePath}");
|
||||
while(IsFileInUse(settings.jobsFilePath))
|
||||
Thread.Sleep(10);
|
||||
File.WriteAllText(settings.jobsFilePath, JsonConvert.SerializeObject(this.jobs));
|
||||
}
|
||||
|
||||
public void CheckJobs()
|
||||
{
|
||||
foreach (Job job in jobs.Where(job => job.nextExecution < DateTime.Now && !QueueContainsJob(job)).OrderBy(job => job.nextExecution))
|
||||
@ -154,7 +158,9 @@ public class JobBoss : GlobalBase
|
||||
queueHead.ResetProgress();
|
||||
jobQueue.Dequeue();
|
||||
}else if (queueHead.progressToken.state is ProgressToken.State.Standby)
|
||||
{
|
||||
AddJobsToQueue(jobQueue.Peek().ExecuteReturnSubTasks());
|
||||
}
|
||||
else if (queueHead.progressToken.state is ProgressToken.State.Cancelled)
|
||||
{
|
||||
switch (queueHead)
|
||||
|
@ -34,6 +34,7 @@ public class JobJsonConverter : JsonConverter
|
||||
}
|
||||
}))!,
|
||||
jo.GetValue("manga")!.ToObject<Manga>(),
|
||||
jo.GetValue("lastExecution")!.ToObject<DateTime>(),
|
||||
jo.GetValue("recurring")!.Value<bool>(),
|
||||
jo.GetValue("recurrenceTime")!.ToObject<TimeSpan?>());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user