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