Delete old jobfiles.
This commit is contained in:
parent
ec9290f41f
commit
d52213002e
@ -171,18 +171,18 @@ public class JobBoss : GlobalBase
|
||||
}
|
||||
}
|
||||
|
||||
internal void UpdateJobFile(Job job)
|
||||
internal void UpdateJobFile(Job job, string? oldFile = null)
|
||||
{
|
||||
string jobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json");
|
||||
string newJobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json");
|
||||
|
||||
if (!this.jobs.Any(jjob => jjob.id == job.id))
|
||||
{
|
||||
try
|
||||
{
|
||||
Log($"Deleting Job-file {jobFilePath}");
|
||||
while(IsFileInUse(jobFilePath))
|
||||
Log($"Deleting Job-file {newJobFilePath}");
|
||||
while(IsFileInUse(newJobFilePath))
|
||||
Thread.Sleep(10);
|
||||
File.Delete(jobFilePath);
|
||||
File.Delete(newJobFilePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -191,11 +191,24 @@ public class JobBoss : GlobalBase
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"Exporting Job {jobFilePath}");
|
||||
Log($"Exporting Job {newJobFilePath}");
|
||||
string jobStr = JsonConvert.SerializeObject(job);
|
||||
while(IsFileInUse(jobFilePath))
|
||||
while(IsFileInUse(newJobFilePath))
|
||||
Thread.Sleep(10);
|
||||
File.WriteAllText(jobFilePath, jobStr);
|
||||
File.WriteAllText(newJobFilePath, jobStr);
|
||||
}
|
||||
|
||||
if(oldFile is not null)
|
||||
try
|
||||
{
|
||||
Log($"Deleting old Job-file {oldFile}");
|
||||
while(IsFileInUse(oldFile))
|
||||
Thread.Sleep(10);
|
||||
File.Delete(oldFile);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,13 +38,20 @@ public class UpdateMetadata : Job
|
||||
this.mangaConnector.CopyCoverFromCacheToDownloadLocation(manga);
|
||||
foreach (Job job in jobBoss.GetJobsLike(publication: this.manga))
|
||||
{
|
||||
string oldFile;
|
||||
if (job is DownloadNewChapters dc)
|
||||
{
|
||||
oldFile = dc.id;
|
||||
dc.manga = this.manga;
|
||||
}
|
||||
else if (job is UpdateMetadata um)
|
||||
{
|
||||
oldFile = um.id;
|
||||
um.manga = this.manga;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
jobBoss.UpdateJobFile(job);
|
||||
jobBoss.UpdateJobFile(job, oldFile);
|
||||
}
|
||||
this.progressToken.Complete();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user