Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

When the DB fails to save, log out all the series the user should look into for constraint issues and push a message to the admins connected to webui. (#687)

Joseph Milazzo6adf09266802
diff --git a/API/Services/Tasks/ScannerService.cs b/API/Services/Tasks/ScannerService.cs
index 3d1d669c2..d82c9579c 100644
--- a/API/Services/Tasks/ScannerService.cs
+++ b/API/Services/Tasks/ScannerService.cs
@@ -301,7 +301,21 @@ namespace API.Services.Tasks
UpdateSeries(series, parsedSeries);
});
- await _unitOfWork.CommitAsync();
+ try
+ {
+ await _unitOfWork.CommitAsync();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogCritical(ex, "[ScannerService] There was an issue writing to the DB. Chunk {ChunkNumber} did not save to DB. If debug mode, series to check will be printed", chunk);
+ foreach (var series in nonLibrarySeries)
+ {
+ _logger.LogDebug("[ScannerService] There may be a constraint issue with {SeriesName}", series.OriginalName);
+ }
+ await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryError,
+ MessageFactory.ScanLibraryError(library.Id));
+ continue;
+ }
_logger.LogInformation(
"[ScannerService] Processed {SeriesStart} - {SeriesEnd} series in {ElapsedScanTime} milliseconds for {LibraryName}",
chunk * chunkInfo.ChunkSize, (chunk * chunkInfo.ChunkSize) + nonLibrarySeries.Count, totalTime, library.Name);
diff --git a/API/SignalR/MessageFactory.cs b/API/SignalR/MessageFactory.cs
index 19fd66f55..0bab0b4da 100644
--- a/API/SignalR/MessageFactory.cs
+++ b/API/SignalR/MessageFactory.cs
@@ -96,5 +96,17 @@ namespace API.SignalR
}
};
}
+
+ public static SignalRMessage ScanLibraryError(int libraryId)
+ {
+ return new SignalRMessage
+ {
+ Name = SignalREvents.ScanLibraryError,
+ Body = new
+ {
+ LibraryId = libraryId,
+ }
+ };
+ }
}
}
diff --git a/API/SignalR/SignalREvents.cs b/API/SignalR/SignalREvents.cs
index d0ce5102e..0f97ad493 100644
--- a/API/SignalR/SignalREvents.cs
+++ b/API/SignalR/SignalREvents.cs
@@ -11,5 +11,6 @@
public const string ScanLibraryProgress = "ScanLibraryProgress";
public const string OnlineUsers = "OnlineUsers";
public const string SeriesAddedToCollection = "SeriesAddedToCollection";
+ public const string ScanLibraryError = "ScanLibraryError";
}
}
diff --git a/UI/Web/src/app/_services/message-hub.service.ts b/UI/Web/src/app/_services/message-hub.service.ts
index dc7490d74..c058e1596 100644
--- a/UI/Web/src/app/_services/message-hub.service.ts
+++ b/UI/Web/src/app/_services/message-hub.service.ts
@@ -18,7 +18,8 @@ export enum EVENTS {
SeriesAdded = 'SeriesAdded',
ScanLibraryProgress = 'ScanLibraryProgress',
OnlineUsers = 'OnlineUsers',
- SeriesAddedToCollection = 'SeriesAddedToCollection'
+ SeriesAddedToCollection = 'SeriesAddedToCollection',
+ ScanLibraryError = 'ScanLibraryError'
}
export interface Message<T> {
@@ -93,6 +94,16 @@ export class MessageHubService {
});
});
+ this.hubConnection.on(EVENTS.ScanLibraryError, resp => {
+ this.messagesSource.next({
+ event: EVENTS.ScanLibraryError,
+ payload: resp.body
+ });
+ if (this.isAdmin) {
+ this.toastr.error('Library Scan had a critical error. Some series were not saved. Check logs');
+ }
+ });
+
this.hubConnection.on(EVENTS.SeriesAdded, resp => {
this.messagesSource.next({
event: EVENTS.SeriesAdded,