BaseWorker, BaseWorkerWithContext DoWork, call: Scope setting

TrangaBaseContext Sync return with success state and exception message
This commit is contained in:
2025-07-02 22:15:34 +02:00
parent 6cd836540a
commit e327e93163
19 changed files with 125 additions and 99 deletions

View File

@ -1,26 +1,20 @@
using API.Schema.MangaContext;
using API.Schema.MangaContext.MangaConnectors;
using Microsoft.EntityFrameworkCore;
namespace API.Workers;
public class DownloadCoverFromMangaconnectorWorker(MangaConnectorId<Manga> mcId, IServiceScope scope, IEnumerable<BaseWorker>? dependsOn = null)
: BaseWorkerWithContext<MangaContext>(scope, dependsOn)
public class DownloadCoverFromMangaconnectorWorker(MangaConnectorId<Manga> mcId, IEnumerable<BaseWorker>? dependsOn = null)
: BaseWorkerWithContext<MangaContext>(dependsOn)
{
public MangaConnectorId<Manga> MangaConnectorId { get; init; } = mcId;
protected override BaseWorker[] DoWorkInternal()
{
MangaConnector mangaConnector = MangaConnectorId.MangaConnector;
Manga manga = MangaConnectorId.Obj;
try
{
manga.CoverFileNameInCache = mangaConnector.SaveCoverImageToCache(MangaConnectorId);
DbContext.SaveChanges();
}
catch (DbUpdateException e)
{
Log.Error(e);
}
manga.CoverFileNameInCache = mangaConnector.SaveCoverImageToCache(MangaConnectorId);
DbContext.Sync();
return [];
}
}