Skip to content

Commit 926f4c4

Browse files
authored
Merge pull request #1382 from danielgerlag/copilot/fix-pending-workflow-issue
Fix workflow consumer greylist removal to prevent workflows stuck in "Pending" status
2 parents 75c440a + f7e3dd9 commit 926f4c4

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/WorkflowCore/Services/BackgroundTasks/WorkflowConsumer.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
namespace WorkflowCore.Services.BackgroundTasks
1010
{
11+
/// <summary>
12+
/// Background task responsible for consuming workflow items from the queue and processing them.
13+
/// This consumer ensures that workflows are removed from the greylist after processing,
14+
/// regardless of their status, to prevent workflows from getting stuck in "Pending" state.
15+
/// </summary>
1116
internal class WorkflowConsumer : QueueConsumer, IBackgroundTask
1217
{
1318
private readonly IDistributedLockProvider _lockProvider;
@@ -57,12 +62,25 @@ protected override async Task ProcessItem(string itemId, CancellationToken cance
5762
WorkflowActivity.Enrich(result);
5863
await _persistenceStore.PersistWorkflow(workflow, result?.Subscriptions, cancellationToken);
5964
await QueueProvider.QueueWork(itemId, QueueType.Index);
60-
_greylist.Remove($"wf:{itemId}");
6165
}
6266
}
67+
else
68+
{
69+
Logger.LogDebug("Workflow {ItemId} is not runnable, status: {Status}", itemId, workflow.Status);
70+
}
71+
}
72+
catch (Exception ex)
73+
{
74+
Logger.LogError(ex, "Error processing workflow {ItemId}", itemId);
75+
throw;
6376
}
6477
finally
6578
{
79+
// Always remove from greylist regardless of workflow status
80+
// This prevents workflows from being stuck in greylist when they can't be processed
81+
Logger.LogDebug("Removing workflow {ItemId} from greylist", itemId);
82+
_greylist.Remove($"wf:{itemId}");
83+
6684
await _lockProvider.ReleaseLock(itemId);
6785
if ((workflow != null) && (result != null))
6886
{

0 commit comments

Comments
 (0)