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)

This commit is contained in:
Joseph Milazzo 2021-10-18 08:45:39 -07:00 committed by GitHub
parent 8b03e1d240
commit 6adf092668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 2 deletions

View File

@ -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);

View File

@ -96,5 +96,17 @@ namespace API.SignalR
}
};
}
public static SignalRMessage ScanLibraryError(int libraryId)
{
return new SignalRMessage
{
Name = SignalREvents.ScanLibraryError,
Body = new
{
LibraryId = libraryId,
}
};
}
}
}

View File

@ -11,5 +11,6 @@
public const string ScanLibraryProgress = "ScanLibraryProgress";
public const string OnlineUsers = "OnlineUsers";
public const string SeriesAddedToCollection = "SeriesAddedToCollection";
public const string ScanLibraryError = "ScanLibraryError";
}
}

View File

@ -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,