Skip to content

Commit 75d91d5

Browse files
Copilotsfmskywalker
andcommitted
Improve: Add comprehensive error handling and logging
Enhanced the fix based on code review feedback: 1. Added error handling at ProcessPageAsync level to ensure one failing item doesn't block processing of other items in the batch 2. Added explicit exception logging in ProcessItemAsync to surface errors during workflow resumption 3. Changed deletion to use CancellationToken.None to ensure cleanup happens even during application shutdown 4. Added detailed comments explaining error handling strategy These improvements ensure the system is robust and provides visibility into any issues while still guaranteeing queue items are cleaned up properly. Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
1 parent 2acd408 commit 75d91d5

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

src/modules/Elsa.Workflows.Runtime/Services/BookmarkQueueProcessor.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,18 @@ public async Task ProcessAsync(CancellationToken cancellationToken = default)
3030

3131
private async Task ProcessPageAsync(Page<BookmarkQueueItem> page, CancellationToken cancellationToken = default)
3232
{
33-
foreach (var bookmarkQueueItem in page.Items)
34-
await ProcessItemAsync(bookmarkQueueItem, cancellationToken);
33+
foreach (var bookmarkQueueItem in page.Items)
34+
{
35+
try
36+
{
37+
await ProcessItemAsync(bookmarkQueueItem, cancellationToken);
38+
}
39+
catch (Exception ex)
40+
{
41+
// Log the error but continue processing other items in the batch
42+
logger.LogError(ex, "Error processing bookmark queue item {BookmarkQueueItemId}. Continuing with next item.", bookmarkQueueItem.Id);
43+
}
44+
}
3545
}
3646

3747
private async Task ProcessItemAsync(BookmarkQueueItem item, CancellationToken cancellationToken = default)
@@ -54,14 +64,19 @@ private async Task ProcessItemAsync(BookmarkQueueItem item, CancellationToken ca
5464
logger.LogDebug("No matching bookmarks found for bookmark queue item {BookmarkQueueItemId} for workflow instance {WorkflowInstanceId} for activity type {ActivityType} with stimulus {StimulusHash}. The bookmark may have already been processed by another queue item.", item.Id, item.WorkflowInstanceId, item.ActivityTypeName, item.StimulusHash);
5565
}
5666
}
67+
catch (Exception ex)
68+
{
69+
logger.LogError(ex, "Error resuming workflow for bookmark queue item {BookmarkQueueItemId} for workflow instance {WorkflowInstanceId}. The queue item will still be deleted to prevent accumulation.", item.Id, item.WorkflowInstanceId);
70+
}
5771
finally
5872
{
5973
// Always delete the queue item after processing, regardless of whether bookmarks were found or an exception occurred.
6074
// This prevents duplicate queue items from accumulating when the same bookmark is queued multiple times in rapid succession.
6175
// The distributed lock in WorkflowResumer ensures that the actual bookmark is only processed once.
76+
// Use CancellationToken.None to ensure cleanup happens even during application shutdown.
6277
try
6378
{
64-
await store.DeleteAsync(item.Id, cancellationToken);
79+
await store.DeleteAsync(item.Id, CancellationToken.None);
6580
}
6681
catch (Exception ex)
6782
{

0 commit comments

Comments
 (0)