From 87ea0772810514b37f67449b3a419ee0520b73e2 Mon Sep 17 00:00:00 2001 From: glax Date: Tue, 19 Sep 2023 20:02:56 +0200 Subject: [PATCH] Remove log clutter and filewrites --- Tranga/Jobs/JobBoss.cs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 477e402..01c4fc5 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -161,18 +161,21 @@ public class JobBoss : GlobalBase cachedPublications.Add(ncJob.manga); } + public void ExportJob(Job job) + { + string jobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json"); + string jobStr = JsonConvert.SerializeObject(job); + while(IsFileInUse(jobFilePath)) + Thread.Sleep(10); + Log($"Exporting Job {jobFilePath}"); + File.WriteAllText(jobFilePath, jobStr); + } + public void ExportJobsList() { Log("Exporting Jobs"); foreach (Job job in this.jobs) - { - string jobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json"); - string jobStr = JsonConvert.SerializeObject(job); - while(IsFileInUse(jobFilePath)) - Thread.Sleep(10); - Log($"Exporting Job {jobFilePath}"); - File.WriteAllText(jobFilePath, jobStr); - } + ExportJob(job); //Remove files with jobs not in this.jobs-list Regex idRex = new (@"(.*)\.json"); @@ -219,14 +222,13 @@ public class JobBoss : GlobalBase } queueHead.ResetProgress(); jobQueue.Dequeue(); - ExportJobsList(); + 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) { Job[] subJobs = jobQueue.Peek().ExecuteReturnSubTasks().ToArray(); AddJobs(subJobs); AddJobsToQueue(subJobs); - ExportJobsList(); } } }