From 00b272e77e3d235d98d03ef12db0f5bea03e31d9 Mon Sep 17 00:00:00 2001 From: rlauu <46294892+rlauu@users.noreply.github.com> Date: Sun, 20 Oct 2024 10:26:38 +0200 Subject: [PATCH] more robust cancelling --- .../ScheduledTasks/BaseItemAnalyzerTask.cs | 15 +++++++++++---- .../Services/Entrypoint.cs | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs index 8edb543..f0f6619 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/BaseItemAnalyzerTask.cs @@ -135,10 +135,7 @@ public class BaseItemAnalyzerTask try { - if (ct.IsCancellationRequested) - { - return; - } + ct.ThrowIfCancellationRequested(); foreach (AnalysisMode mode in requiredModes) { @@ -150,6 +147,10 @@ public class BaseItemAnalyzerTask progress.Report(totalProcessed * 100 / totalQueued); } } + catch (OperationCanceledException ex) + { + _logger.LogDebug(ex, "Analysis cancelled"); + } catch (FingerprintException ex) { _logger.LogWarning( @@ -158,6 +159,11 @@ public class BaseItemAnalyzerTask first.SeasonNumber, ex); } + catch (Exception ex) + { + _logger.LogError(ex, "An unexpected error occurred during analysis"); + throw; + } if (Plugin.Instance.Configuration.RegenerateMediaSegments || (updateManagers && Plugin.Instance.Configuration.UpdateMediaSegments)) { @@ -238,6 +244,7 @@ public class BaseItemAnalyzerTask foreach (var analyzer in analyzers) { items = analyzer.AnalyzeMediaFiles(items, mode, cancellationToken); + cancellationToken.ThrowIfCancellationRequested(); } // Add items without intros/credits to blacklist. diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Services/Entrypoint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Services/Entrypoint.cs index cbca925..6f72cf1 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Services/Entrypoint.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Services/Entrypoint.cs @@ -164,6 +164,10 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper.Services { await PerformAnalysisAsync().ConfigureAwait(false); } + catch (OperationCanceledException) + { + _logger.LogInformation("Automatic Analysis task cancelled"); + } catch (Exception ex) { _logger.LogError(ex, "Error in RunAnalysisAsync");