mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-10 20:08:19 +02:00
Fix CancellationToken Source crashing all Workers after 10 Minutes of runtime
This commit is contained in:
@@ -123,24 +123,25 @@ public static class Tranga
|
||||
Log.Fatal("ServiceProvider is null");
|
||||
return;
|
||||
}
|
||||
Action callBack = AfterWork(worker, callback);
|
||||
Action afterWorkCallback = AfterWork(worker, callback);
|
||||
|
||||
if (worker is BaseWorkerWithContext<MangaContext> mangaContextWorker)
|
||||
{
|
||||
mangaContextWorker.SetScope(ServiceProvider.CreateScope());
|
||||
RunningWorkers.TryAdd(mangaContextWorker, mangaContextWorker.DoWork(callBack));
|
||||
RunningWorkers.TryAdd(mangaContextWorker, mangaContextWorker.DoWork(afterWorkCallback));
|
||||
}else if (worker is BaseWorkerWithContext<NotificationsContext> notificationContextWorker)
|
||||
{
|
||||
notificationContextWorker.SetScope(ServiceProvider.CreateScope());
|
||||
RunningWorkers.TryAdd(notificationContextWorker, notificationContextWorker.DoWork(callBack));
|
||||
RunningWorkers.TryAdd(notificationContextWorker, notificationContextWorker.DoWork(afterWorkCallback));
|
||||
}else if (worker is BaseWorkerWithContext<LibraryContext> libraryContextWorker)
|
||||
{
|
||||
libraryContextWorker.SetScope(ServiceProvider.CreateScope());
|
||||
RunningWorkers.TryAdd(libraryContextWorker, libraryContextWorker.DoWork(callBack));
|
||||
RunningWorkers.TryAdd(libraryContextWorker, libraryContextWorker.DoWork(afterWorkCallback));
|
||||
}else
|
||||
RunningWorkers.TryAdd(worker, worker.DoWork(callBack));
|
||||
RunningWorkers.TryAdd(worker, worker.DoWork(afterWorkCallback));
|
||||
}
|
||||
|
||||
private static Action AfterWork(BaseWorker worker, Action? callback) => () =>
|
||||
private static Action AfterWork(BaseWorker worker, Action? callback = null) => () =>
|
||||
{
|
||||
Log.Debug($"AfterWork {worker}");
|
||||
RunningWorkers.Remove(worker, out _);
|
||||
|
Reference in New Issue
Block a user