more robust cancelling

This commit is contained in:
rlauu 2024-10-20 10:26:38 +02:00
parent 1a731e3acc
commit 00b272e77e
2 changed files with 15 additions and 4 deletions

View File

@ -135,10 +135,7 @@ public class BaseItemAnalyzerTask
try try
{ {
if (ct.IsCancellationRequested) ct.ThrowIfCancellationRequested();
{
return;
}
foreach (AnalysisMode mode in requiredModes) foreach (AnalysisMode mode in requiredModes)
{ {
@ -150,6 +147,10 @@ public class BaseItemAnalyzerTask
progress.Report(totalProcessed * 100 / totalQueued); progress.Report(totalProcessed * 100 / totalQueued);
} }
} }
catch (OperationCanceledException ex)
{
_logger.LogDebug(ex, "Analysis cancelled");
}
catch (FingerprintException ex) catch (FingerprintException ex)
{ {
_logger.LogWarning( _logger.LogWarning(
@ -158,6 +159,11 @@ public class BaseItemAnalyzerTask
first.SeasonNumber, first.SeasonNumber,
ex); ex);
} }
catch (Exception ex)
{
_logger.LogError(ex, "An unexpected error occurred during analysis");
throw;
}
if (Plugin.Instance.Configuration.RegenerateMediaSegments || (updateManagers && Plugin.Instance.Configuration.UpdateMediaSegments)) if (Plugin.Instance.Configuration.RegenerateMediaSegments || (updateManagers && Plugin.Instance.Configuration.UpdateMediaSegments))
{ {
@ -238,6 +244,7 @@ public class BaseItemAnalyzerTask
foreach (var analyzer in analyzers) foreach (var analyzer in analyzers)
{ {
items = analyzer.AnalyzeMediaFiles(items, mode, cancellationToken); items = analyzer.AnalyzeMediaFiles(items, mode, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
} }
// Add items without intros/credits to blacklist. // Add items without intros/credits to blacklist.

View File

@ -164,6 +164,10 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper.Services
{ {
await PerformAnalysisAsync().ConfigureAwait(false); await PerformAnalysisAsync().ConfigureAwait(false);
} }
catch (OperationCanceledException)
{
_logger.LogInformation("Automatic Analysis task cancelled");
}
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Error in RunAnalysisAsync"); _logger.LogError(ex, "Error in RunAnalysisAsync");