mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-23 07:40:13 +01:00
Job Run pass context to add new Data
This commit is contained in:
parent
9cb5f636dd
commit
16dd1ffa97
@ -18,7 +18,7 @@ public class DownloadSingleChapterJob(string chapterId, string? parentJobId = nu
|
||||
public string ChapterId { get; init; } = chapterId;
|
||||
public virtual Chapter Chapter { get; init; }
|
||||
|
||||
protected override IEnumerable<Job> RunInternal()
|
||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
||||
{
|
||||
MangaConnector connector = Chapter.ParentManga.MangaConnector;
|
||||
DownloadChapterImages(Chapter);
|
||||
@ -50,8 +50,6 @@ public class DownloadSingleChapterJob(string chapterId, string? parentJobId = nu
|
||||
//Download all Images to temporary Folder
|
||||
if (imageUrls.Length == 0)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
File.SetUnixFileMode(saveArchiveFilePath, UserRead | UserWrite | UserExecute | GroupRead | GroupWrite | GroupExecute);
|
||||
Directory.Delete(tempFolder, true);
|
||||
return false;
|
||||
}
|
||||
|
@ -36,13 +36,13 @@ public abstract class Job
|
||||
NextExecution = LastExecution.AddMilliseconds(RecurrenceMs);
|
||||
}
|
||||
|
||||
public IEnumerable<Job> Run()
|
||||
public IEnumerable<Job> Run(PgsqlContext context)
|
||||
{
|
||||
this.state = JobState.Running;
|
||||
IEnumerable<Job> newJobs = RunInternal();
|
||||
IEnumerable<Job> newJobs = RunInternal(context);
|
||||
this.state = JobState.Completed;
|
||||
return newJobs;
|
||||
}
|
||||
|
||||
protected abstract IEnumerable<Job> RunInternal();
|
||||
protected abstract IEnumerable<Job> RunInternal(PgsqlContext context);
|
||||
}
|
@ -6,7 +6,7 @@ public class MoveFileOrFolderJob(string fromLocation, string toLocation, string?
|
||||
public string FromLocation { get; init; } = fromLocation;
|
||||
public string ToLocation { get; init; } = toLocation;
|
||||
|
||||
protected override IEnumerable<Job> RunInternal()
|
||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ public class UpdateMetadataJob(ulong recurrenceMs, string mangaId, string? paren
|
||||
public string MangaId { get; init; } = mangaId;
|
||||
public virtual Manga Manga { get; init; }
|
||||
|
||||
protected override IEnumerable<Job> RunInternal()
|
||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -63,7 +63,6 @@ public static class Tranga
|
||||
|
||||
string TRANGA = "\n\n _______ \n|_ _|.----..---.-..-----..-----..---.-.\n | | | _|| _ || || _ || _ |\n |___| |__| |___._||__|__||___ ||___._|\n |_____| \n\n";
|
||||
Log.Info(TRANGA);
|
||||
List<Job> newJobs = new();
|
||||
while (true)
|
||||
{
|
||||
List<Job> completedJobs = context.Jobs.Where(j => j.state == JobState.Completed).ToList();
|
||||
@ -82,14 +81,13 @@ public static class Tranga
|
||||
{
|
||||
Thread t = new (() =>
|
||||
{
|
||||
newJobs.AddRange(job.Run());
|
||||
IEnumerable<Job> newJobs = job.Run(context);
|
||||
context.Jobs.AddRange(newJobs);
|
||||
});
|
||||
RunningJobs.Add(t, job);
|
||||
t.Start();
|
||||
context.Jobs.Update(job);
|
||||
}
|
||||
context.Jobs.AddRange(newJobs);
|
||||
newJobs.Clear();
|
||||
|
||||
(Thread, Job)[] removeFromThreadsList = RunningJobs.Where(t => !t.Key.IsAlive)
|
||||
.Select(t => (t.Key, t.Value)).ToArray();
|
||||
|
Loading…
x
Reference in New Issue
Block a user