Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Do not log TaskCanceledException on sigterm signal.
nzbdav-devb5c8a7dded23
diff --git a/backend/Services/BlobCleanupService.cs b/backend/Services/BlobCleanupService.csindex dc664830..e6351663 100644--- a/backend/Services/BlobCleanupService.cs+++ b/backend/Services/BlobCleanupService.cs@@ -1,6 +1,7 @@using Microsoft.EntityFrameworkCore;using Microsoft.Extensions.Hosting;using NzbWebDAV.Database;+using NzbWebDAV.Utils;using Serilog;namespace NzbWebDAV.Services;@@ -40,6 +41,11 @@ public class BlobCleanupService : BackgroundService// Continue immediately to next iteration to process more items}+ catch (OperationCanceledException) when (SigtermUtil.IsSigtermTriggered())+ {+ // OperationCanceledException is expected on sigterm+ return;+ }catch (Exception e){Log.Error(e, $"Error processing blob cleanup queue: {e.Message}");diff --git a/backend/Services/DavCleanupService.cs b/backend/Services/DavCleanupService.csindex 249f1b72..deab89b3 100644--- a/backend/Services/DavCleanupService.cs+++ b/backend/Services/DavCleanupService.cs@@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore;using Microsoft.Extensions.Hosting;using NzbWebDAV.Database;using NzbWebDAV.Database.Models;+using NzbWebDAV.Utils;using Serilog;namespace NzbWebDAV.Services;@@ -48,6 +49,11 @@ public class DavCleanupService : BackgroundService// Continue immediately to next iteration to process more items}+ catch (OperationCanceledException) when (SigtermUtil.IsSigtermTriggered())+ {+ // OperationCanceledException is expected on sigterm+ return;+ }catch (Exception e){Log.Error(e, $"Error processing dav cleanup queue: {e.Message}");diff --git a/backend/Services/HealthCheckService.cs b/backend/Services/HealthCheckService.csindex a2baeb2b..d7528402 100644--- a/backend/Services/HealthCheckService.cs+++ b/backend/Services/HealthCheckService.cs@@ -78,6 +78,11 @@ public class HealthCheckService : BackgroundService// perform the health checkawait PerformHealthCheck(davItem, dbClient, concurrency, cts.Token).ConfigureAwait(false);}+ catch (OperationCanceledException) when (SigtermUtil.IsSigtermTriggered())+ {+ // OperationCanceledException is expected on sigterm+ return;+ }catch (Exception e){Log.Error(e, $"Unexpected error performing background health checks: {e.Message}");diff --git a/backend/Services/HistoryCleanupService.cs b/backend/Services/HistoryCleanupService.csindex 5ea1a4de..8b7ebe8c 100644--- a/backend/Services/HistoryCleanupService.cs+++ b/backend/Services/HistoryCleanupService.cs@@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore;using Microsoft.Extensions.Hosting;using NzbWebDAV.Database;using NzbWebDAV.Database.Models;+using NzbWebDAV.Utils;using Serilog;namespace NzbWebDAV.Services;@@ -61,6 +62,11 @@ public class HistoryCleanupService : BackgroundService// Continue immediately to next iteration to process more items}+ catch (OperationCanceledException) when (SigtermUtil.IsSigtermTriggered())+ {+ // OperationCanceledException is expected on sigterm+ return;+ }catch (Exception e){Log.Error(e, $"Error processing history cleanup queue: {e.Message}");diff --git a/backend/Services/NzbBlobCleanupService.cs b/backend/Services/NzbBlobCleanupService.csindex 91ab4bb7..c6fcad9d 100644--- a/backend/Services/NzbBlobCleanupService.cs+++ b/backend/Services/NzbBlobCleanupService.cs@@ -2,6 +2,7 @@ using System.Data;using Microsoft.EntityFrameworkCore;using Microsoft.Extensions.Hosting;using NzbWebDAV.Database;+using NzbWebDAV.Utils;using Serilog;namespace NzbWebDAV.Services;@@ -81,6 +82,11 @@ public class NzbBlobCleanupService : BackgroundService// Continue immediately to next iteration to process more items}+ catch (OperationCanceledException) when (SigtermUtil.IsSigtermTriggered())+ {+ // OperationCanceledException is expected on sigterm+ return;+ }catch (Exception e){Log.Error(e, $"Error processing NZB blob cleanup queue: {e.Message}");diff --git a/backend/Utils/SigtermUtil.cs b/backend/Utils/SigtermUtil.csindex 4c6ee94b..68134f2f 100644--- a/backend/Utils/SigtermUtil.cs+++ b/backend/Utils/SigtermUtil.cs@@ -40,6 +40,11 @@ public static class SigtermUtilreturn CancellationTokenSource.Token;}+ public static bool IsSigtermTriggered()+ {+ return GetCancellationToken().IsCancellationRequested;+ }+public static void Cancel(){CancellationTokenSource.Cancel();