Better sync log

This commit is contained in:
2025-09-18 02:04:01 +02:00
parent c199f37b14
commit 429cd2284f
18 changed files with 30 additions and 29 deletions

View File

@@ -71,7 +71,7 @@ public class FileLibraryController(MangaContext context) : Controller
//TODO Path check
library.BasePath = newBasePath;
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Ok();
}
@@ -96,7 +96,7 @@ public class FileLibraryController(MangaContext context) : Controller
//TODO Name check
library.LibraryName = newName;
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Ok();
}
@@ -113,10 +113,10 @@ public class FileLibraryController(MangaContext context) : Controller
public async Task<Results<Created<string>, InternalServerError<string>>> CreateNewLibrary ([FromBody]CreateLibraryRecord requestData)
{
//TODO Parameter check
Schema.MangaContext.FileLibrary library = new Schema.MangaContext.FileLibrary(requestData.BasePath, requestData.LibraryName);
Schema.MangaContext.FileLibrary library = new (requestData.BasePath, requestData.LibraryName);
context.FileLibraries.Add(library);
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Created(string.Empty, library.Key);
@@ -140,7 +140,7 @@ public class FileLibraryController(MangaContext context) : Controller
context.FileLibraries.Remove(library);
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Ok();
}

View File

@@ -72,7 +72,7 @@ public class LibraryConnectorController(LibraryContext context) : Controller
context.LibraryConnectors.Add(connector);
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Created(string.Empty, connector.Key);
}
@@ -95,7 +95,7 @@ public class LibraryConnectorController(LibraryContext context) : Controller
context.LibraryConnectors.Remove(connector);
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Ok();
}

View File

@@ -32,7 +32,7 @@ public class MaintenanceController(MangaContext mangaContext) : Controller
mangaContext.Mangas.RemoveRange(noDownloads);
if(await mangaContext.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await mangaContext.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Ok();
}

View File

@@ -90,7 +90,7 @@ public class MangaConnectorController(MangaContext context) : Controller
connector.Enabled = Enabled;
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Ok();
}

View File

@@ -154,7 +154,7 @@ public class MangaController(MangaContext context) : Controller
context.Mangas.Remove(manga);
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Ok();
}
@@ -420,7 +420,7 @@ public class MangaController(MangaContext context) : Controller
return TypedResults.NotFound(nameof(MangaId));
manga.IgnoreChaptersBefore = chapterThreshold;
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Ok();
@@ -488,7 +488,7 @@ public class MangaController(MangaContext context) : Controller
}
mcId.UseForDownload = IsRequested;
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
DownloadCoverFromMangaconnectorWorker downloadCover = new(mcId);

View File

@@ -91,7 +91,7 @@ public class MetadataFetcherController(MangaContext context) : Controller
MetadataEntry entry = fetcher.CreateMetadataEntry(manga, Identifier);
context.MetadataEntries.Add(entry);
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Ok(entry);
}
@@ -122,7 +122,7 @@ public class MetadataFetcherController(MangaContext context) : Controller
context.Remove(entry);
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Ok();
}

View File

@@ -72,7 +72,7 @@ public class NotificationConnectorController(NotificationsContext context) : Con
context.NotificationConnectors.Add(newConnector);
context.Notifications.Add(new ("Added new Notification Connector!", newConnector.Name, NotificationUrgency.High));
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Created(string.Empty, newConnector.Name);
}
@@ -168,7 +168,7 @@ public class NotificationConnectorController(NotificationsContext context) : Con
context.NotificationConnectors.Remove(connector);
if(await context.Sync(HttpContext.RequestAborted) is { success: false } result)
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
return TypedResults.InternalServerError(result.exceptionMessage);
return TypedResults.Ok();
}

View File

@@ -84,7 +84,7 @@ public class Chapter : Identifiable, IComparable<Chapter>
//TODO Log here
this.Downloaded = File.Exists(chapter.FullArchiveFilePath);
await context.Sync(token??CancellationToken.None);
await context.Sync(token??CancellationToken.None, GetType());
return this.Downloaded;
}

View File

@@ -85,7 +85,7 @@ public class MyAnimeList : MetadataFetcher
dbManga.Authors.Clear();
dbManga.Authors = resultData.Authors.Select(a => new Author(a.Name)).ToList();
await dbContext.Sync(token);
await dbContext.Sync(token, GetType());
}
}

View File

@@ -1,3 +1,4 @@
using API.Workers;
using log4net;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
@@ -22,9 +23,9 @@ public abstract class TrangaBaseContext<T> : DbContext where T : DbContext
}, Array.Empty<string>(), LogLevel.Warning, DbContextLoggerOptions.Level | DbContextLoggerOptions.Category | DbContextLoggerOptions.UtcTime);
}
internal async Task<(bool success, string? exceptionMessage)> Sync(CancellationToken token)
internal async Task<(bool success, string? exceptionMessage)> Sync(CancellationToken token, Type? trigger = null)
{
Log.Debug($"Syncing {GetType().Name}...");
Log.Debug($"Syncing {GetType().Name} {trigger?.Name}...");
try
{
int changedRows = await this.SaveChangesAsync(token);

View File

@@ -67,7 +67,7 @@ public class DownloadChapterFromMangaconnectorWorker(MangaConnectorId<Chapter> c
{
Log.Info($"No imageUrls for chapter {chapter}");
mangaConnectorId.UseForDownload = false; // Do not try to download from this again
if(await DbContext.Sync(CancellationToken) is { success: false } result)
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } result)
Log.Error(result.exceptionMessage);
return [];
}
@@ -132,7 +132,7 @@ public class DownloadChapterFromMangaconnectorWorker(MangaConnectorId<Chapter> c
Directory.Delete(tempFolder, true); //Cleanup
DbContext.Entry(chapter).Property(c => c.Downloaded).CurrentValue = true;
if(await DbContext.Sync(CancellationToken) is { success: false } e)
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
Log.Debug($"Downloaded chapter {chapter}.");

View File

@@ -37,7 +37,7 @@ public class DownloadCoverFromMangaconnectorWorker(MangaConnectorId<Manga> mcId,
}
DbContext.Entry(mangaConnectorId.Obj).Property(m => m.CoverFileNameInCache).CurrentValue = coverFileName;
if(await DbContext.Sync(CancellationToken) is { success: false } e)
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
return [];

View File

@@ -73,7 +73,7 @@ public class RetrieveMangaChaptersFromMangaconnectorWorker(MangaConnectorId<Mang
}
}
if(await DbContext.Sync(CancellationToken) is { success: false } e)
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
return [];

View File

@@ -35,7 +35,7 @@ public class MoveMangaLibraryWorker(Manga manga, FileLibrary toLibrary, IEnumera
// Set new Path
manga.Library = toLibrary;
if (await DbContext.Sync(CancellationToken) is { success: false })
if (await DbContext.Sync(CancellationToken, GetType()) is { success: false })
return [];
// Create Jobs to move chapters from old to new Path

View File

@@ -19,7 +19,7 @@ public class RemoveOldNotificationsWorker(TimeSpan? interval = null, IEnumerable
Log.Debug($"Removing {toRemove.Count} old notifications...");
DbContext.RemoveRange(toRemove);
if(await DbContext.Sync(CancellationToken) is { success: false } e)
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
return [];

View File

@@ -33,7 +33,7 @@ public class SendNotificationsWorker(TimeSpan? interval = null, IEnumerable<Base
Log.Debug("Notifications sent.");
if(await DbContext.Sync(CancellationToken) is { success: false } e)
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
return [];

View File

@@ -28,7 +28,7 @@ public class UpdateChaptersDownloadedWorker(TimeSpan? interval = null, IEnumerab
}
}
if(await DbContext.Sync(CancellationToken) is { success: false } e)
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
return [];

View File

@@ -37,7 +37,7 @@ public class UpdateMetadataWorker(TimeSpan? interval = null, IEnumerable<BaseWor
}
Log.Debug("Updated metadata.");
if(await DbContext.Sync(CancellationToken) is { success: false } e)
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
return [];