2
0

Added lastExecution time on jobs.json parse

This commit is contained in:
glax 2023-09-02 15:05:15 +02:00
parent ae5be31c89
commit 79bbc92467
4 changed files with 35 additions and 8 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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)

View File

@ -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?>());
}