Skip to content

Commit f6b319a

Browse files
committed
More graceful shutdown
1 parent deb3ee0 commit f6b319a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/QueuedHostedService.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ private async Task TaskProcessing(CancellationToken cancellationToken)
7777
if (_log)
7878
_logger.LogDebug("~~ QueuedHostedService: Completed Task: {item}", workItemName);
7979
}
80+
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
81+
{
82+
// Ignore cancellation exception during shutdown if no task was being processed
83+
if (workItem != null)
84+
_logger.LogError("~~ QueuedHostedService: Task was cancelled while executing!: {item}", workItem?.Method.GetSignature());
85+
}
8086
catch (Exception ex)
8187
{
8288
_logger.LogError(ex, "~~ QueuedHostedService:: Error executing Task: {item}", workItem?.Method.GetSignature());
@@ -111,6 +117,12 @@ private async Task ValueTaskProcessing(CancellationToken cancellationToken)
111117
if (_log)
112118
_logger.LogDebug("~~ QueuedHostedService: Completed ValueTask: {item}", workItemName);
113119
}
120+
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
121+
{
122+
// Ignore cancellation exception during shutdown if no ValueTask was being processed
123+
if (workItem != null)
124+
_logger.LogError("~~ QueuedHostedService: ValueTask was cancelled while executing!: {item}", workItem?.Method.GetSignature());
125+
}
114126
catch (Exception ex)
115127
{
116128
_logger.LogError(ex, "~~ QueuedHostedService: Error executing ValueTask: {item}", workItem?.Method.GetSignature());

0 commit comments

Comments
 (0)