mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-10 11:58:19 +02:00
Improved CancellationToken usage, Added more logging to Workers, Added Code-comments (please future me, be thankful)
This commit is contained in:
@@ -3,6 +3,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Workers;
|
||||
|
||||
/// <summary>
|
||||
/// Updates the database to reflect changes made on disk
|
||||
/// </summary>
|
||||
public class UpdateChaptersDownloadedWorker(TimeSpan? interval = null, IEnumerable<BaseWorker>? dependsOn = null)
|
||||
: BaseWorkerWithContext<MangaContext>(dependsOn), IPeriodic
|
||||
{
|
||||
@@ -10,10 +13,14 @@ public class UpdateChaptersDownloadedWorker(TimeSpan? interval = null, IEnumerab
|
||||
public TimeSpan Interval { get; set; } = interval??TimeSpan.FromMinutes(60);
|
||||
protected override async Task<BaseWorker[]> DoWorkInternal()
|
||||
{
|
||||
foreach (Chapter dbContextChapter in DbContext.Chapters.Include(c => c.ParentManga))
|
||||
dbContextChapter.Downloaded = dbContextChapter.CheckDownloaded();
|
||||
Log.Debug("Checking chapter files...");
|
||||
List<Chapter> chapters = await DbContext.Chapters.Include(c => c.ParentManga).ToListAsync(CancellationToken);
|
||||
Log.Debug($"Checking {chapters.Count} chapters...");
|
||||
chapters.ForEach(chapter => DbContext.Entry(chapter).Property(c => c.Downloaded).CurrentValue = chapter.CheckDownloaded());
|
||||
|
||||
await DbContext.Sync(CancellationTokenSource.Token);
|
||||
if(await DbContext.Sync(CancellationToken) is { success: false } e)
|
||||
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user