Move Configuration of Workers to separate method

This commit is contained in:
2025-07-20 19:19:06 +02:00
parent 9d84716278
commit fb004657eb
2 changed files with 13 additions and 2 deletions

View File

@@ -145,6 +145,8 @@ using (IServiceScope scope = app.Services.CreateScope())
Tranga.StartLogger(); Tranga.StartLogger();
Tranga.AddDefaultWorkers();
Tranga.PeriodicWorkerStarterThread.Start(app.Services); Tranga.PeriodicWorkerStarterThread.Start(app.Services);
app.UseCors("AllowAll"); app.UseCors("AllowAll");

View File

@@ -40,7 +40,10 @@ public static class Tranga
BasicConfigurator.Configure(); BasicConfigurator.Configure();
Log.Info("Logger Configured."); Log.Info("Logger Configured.");
Log.Info(TRANGA); Log.Info(TRANGA);
}
internal static void AddDefaultWorkers()
{
AddWorker(UpdateMetadataWorker); AddWorker(UpdateMetadataWorker);
AddWorker(SendNotificationsWorker); AddWorker(SendNotificationsWorker);
AddWorker(UpdateChaptersDownloadedWorker); AddWorker(UpdateChaptersDownloadedWorker);
@@ -51,7 +54,12 @@ public static class Tranga
} }
internal static HashSet<BaseWorker> AllWorkers { get; private set; } = new (); internal static HashSet<BaseWorker> AllWorkers { get; private set; } = new ();
public static void AddWorker(BaseWorker worker) => AllWorkers.Add(worker);
public static void AddWorker(BaseWorker worker)
{
Log.Debug($"Adding {worker} to AllWorkers.");
AllWorkers.Add(worker);
}
public static void AddWorkers(IEnumerable<BaseWorker> workers) public static void AddWorkers(IEnumerable<BaseWorker> workers)
{ {
foreach (BaseWorker baseWorker in workers) foreach (BaseWorker baseWorker in workers)
@@ -67,6 +75,7 @@ public static class Tranga
foreach (BaseWorker worker in baseWorkers) foreach (BaseWorker worker in baseWorkers)
{ {
StopWorker(worker); StopWorker(worker);
Log.Debug($"Removing {removeWorker} from AllWorkers.");
AllWorkers.Remove(worker); AllWorkers.Remove(worker);
} }
} }