mirror of
https://github.com/C9Glax/tranga.git
synced 2025-10-17 19:00:45 +02:00
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using API.Schema.MangaContext;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -7,20 +8,29 @@ namespace API.Workers.PeriodicWorkers;
|
||||
/// Updates the database to reflect changes made on disk
|
||||
/// </summary>
|
||||
public class UpdateChaptersDownloadedWorker(TimeSpan? interval = null, IEnumerable<BaseWorker>? dependsOn = null)
|
||||
: BaseWorkerWithContext<MangaContext>(dependsOn), IPeriodic
|
||||
: BaseWorkerWithContexts(dependsOn), IPeriodic
|
||||
{
|
||||
public DateTime LastExecution { get; set; } = DateTime.UnixEpoch;
|
||||
public TimeSpan Interval { get; set; } = interval??TimeSpan.FromDays(1);
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
private MangaContext MangaContext = null!;
|
||||
|
||||
protected override void SetContexts(IServiceScope serviceScope)
|
||||
{
|
||||
MangaContext = GetContext<MangaContext>(serviceScope);
|
||||
}
|
||||
|
||||
protected override async Task<BaseWorker[]> DoWorkInternal()
|
||||
{
|
||||
Log.Debug("Checking chapter files...");
|
||||
List<Chapter> chapters = await DbContext.Chapters.ToListAsync(CancellationToken);
|
||||
List<Chapter> chapters = await MangaContext.Chapters.ToListAsync(CancellationToken);
|
||||
Log.Debug($"Checking {chapters.Count} chapters...");
|
||||
foreach (Chapter chapter in chapters)
|
||||
{
|
||||
try
|
||||
{
|
||||
chapter.Downloaded = await chapter.CheckDownloaded(DbContext, CancellationToken);
|
||||
chapter.Downloaded = await chapter.CheckDownloaded(MangaContext, CancellationToken);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -28,7 +38,7 @@ public class UpdateChaptersDownloadedWorker(TimeSpan? interval = null, IEnumerab
|
||||
}
|
||||
}
|
||||
|
||||
if(await DbContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } e)
|
||||
if(await MangaContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } e)
|
||||
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
|
||||
|
||||
return [];
|
||||
|
Reference in New Issue
Block a user