Actions initial commit
Some checks failed
Docker Image CI / build (push) Has been cancelled

This commit is contained in:
2025-10-16 02:52:04 +02:00
parent 13fb917c5d
commit 53276e858b
36 changed files with 1013 additions and 169 deletions

View File

@@ -1,4 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using API.MangaConnectors;
using API.Schema.ActionsContext;
using API.Schema.ActionsContext.Actions;
using API.Schema.MangaContext;
using Microsoft.EntityFrameworkCore;
@@ -8,16 +11,28 @@ namespace API.Workers.MangaDownloadWorkers;
/// Downloads the cover for Manga from Mangaconnector
/// </summary>
public class DownloadCoverFromMangaconnectorWorker(MangaConnectorId<Manga> mcId, IEnumerable<BaseWorker>? dependsOn = null)
: BaseWorkerWithContext<MangaContext>(dependsOn)
: BaseWorkerWithContexts(dependsOn)
{
internal readonly string MangaConnectorIdId = mcId.Key;
private readonly string _mangaConnectorIdId = mcId.Key;
[SuppressMessage("ReSharper", "InconsistentNaming")]
private MangaContext MangaContext = null!;
[SuppressMessage("ReSharper", "InconsistentNaming")]
private ActionsContext ActionsContext = null!;
protected override void SetContexts(IServiceScope serviceScope)
{
MangaContext = GetContext<MangaContext>(serviceScope);
ActionsContext = GetContext<ActionsContext>(serviceScope);
}
protected override async Task<BaseWorker[]> DoWorkInternal()
{
Log.Debug($"Getting Cover for MangaConnectorId {MangaConnectorIdId}...");
Log.Debug($"Getting Cover for MangaConnectorId {_mangaConnectorIdId}...");
// Getting MangaConnector info
if (await DbContext.MangaConnectorToManga
if (await MangaContext.MangaConnectorToManga
.Include(id => id.Obj)
.FirstOrDefaultAsync(c => c.Key == MangaConnectorIdId, CancellationToken) is not { } mangaConnectorId)
.FirstOrDefaultAsync(c => c.Key == _mangaConnectorIdId, CancellationToken) is not { } mangaConnectorId)
{
Log.Error("Could not get MangaConnectorId.");
return []; //TODO Exception?
@@ -35,13 +50,17 @@ public class DownloadCoverFromMangaconnectorWorker(MangaConnectorId<Manga> mcId,
Log.Error($"Could not get Cover for MangaConnectorId {mangaConnectorId}.");
return [];
}
DbContext.Entry(mangaConnectorId.Obj).Property(m => m.CoverFileNameInCache).CurrentValue = coverFileName;
MangaContext.Entry(mangaConnectorId.Obj).Property(m => m.CoverFileNameInCache).CurrentValue = coverFileName;
if(await DbContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } e)
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
if(await MangaContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } mangaContextException)
Log.Error($"Failed to save database changes: {mangaContextException.exceptionMessage}");
ActionsContext.Actions.Add(new CoverDownloadedActionRecord(mcId.Obj, coverFileName));
if(await MangaContext.Sync(CancellationToken, GetType(), "Download complete") is { success: false } actionsContextException)
Log.Error($"Failed to save database changes: {actionsContextException.exceptionMessage}");
return [];
}
public override string ToString() => $"{base.ToString()} {MangaConnectorIdId}";
public override string ToString() => $"{base.ToString()} {_mangaConnectorIdId}";
}