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,3 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using API.Schema.ActionsContext;
using API.Schema.ActionsContext.Actions;
using API.Schema.MangaContext;
using API.Schema.MangaContext.MetadataFetchers;
using Microsoft.EntityFrameworkCore;
@@ -10,20 +13,31 @@ namespace API.Workers.PeriodicWorkers;
/// <param name="interval"></param>
/// <param name="dependsOn"></param>
public class UpdateMetadataWorker(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.FromHours(12);
[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("Updating metadata...");
// Get MetadataEntries of Manga marked for download
List<MetadataEntry> metadataEntriesToUpdate = await DbContext.MangaConnectorToManga
List<MetadataEntry> metadataEntriesToUpdate = await MangaContext.MangaConnectorToManga
.Where(m => m.UseForDownload) // Get marked Manga
.Join(
DbContext.MetadataEntries.Include(e => e.MetadataFetcher).Include(e => e.Manga),
MangaContext.MetadataEntries.Include(e => e.MetadataFetcher).Include(e => e.Manga),
mcId => mcId.ObjId,
e => e.MangaId,
(mcId, e) => e) // return MetadataEntry
@@ -33,12 +47,16 @@ public class UpdateMetadataWorker(TimeSpan? interval = null, IEnumerable<BaseWor
foreach (MetadataEntry metadataEntry in metadataEntriesToUpdate)
{
Log.Debug($"Updating metadata of {metadataEntry}...");
await metadataEntry.MetadataFetcher.UpdateMetadata(metadataEntry, DbContext, CancellationToken);
await metadataEntry.MetadataFetcher.UpdateMetadata(metadataEntry, MangaContext, CancellationToken);
ActionsContext.Actions.Add(new MetadataUpdatedActionRecord(metadataEntry.Manga, metadataEntry.MetadataFetcher));
}
Log.Debug("Updated metadata.");
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}");
if(await ActionsContext.Sync(CancellationToken, GetType(), "Metadata Updated") is { success: false } actionsContextException)
Log.Error($"Failed to save database changes: {actionsContextException.exceptionMessage}");
return [];
}