Skip to content

Commit

Permalink
Move scheduling maintenance before dequeued, otherwise a handler coul…
Browse files Browse the repository at this point in the history
…d consume all the time and maintenance to auto abandon never happens.
  • Loading branch information
niemyjski committed Mar 20, 2024
1 parent fb90e45 commit a8348a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Foundatio.TestHarness/Queue/QueueTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1605,12 +1605,17 @@ await queue.StartWorkingAsync(async (item) =>
do
{
if (stats.Abandoned > 0)
{
_logger.LogTrace("Breaking, queue item was abandoned");
break;
}
stats = await queue.GetQueueStatsAsync();
_logger.LogTrace("Getting updated stats, Abandoned={Abandoned}", stats.Abandoned);
await Task.Delay(50, cancellationTokenSource.Token);
} while (sw.Elapsed < TimeSpan.FromSeconds(5));
_logger.LogDebug("Asserting abandon count is 1, {Actual}", stats.Abandoned);
Assert.Equal(1, stats.Abandoned);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Foundatio/Queues/InMemoryQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ protected override async Task<IQueueEntry<T>> DequeueImplAsync(CancellationToken
_logger.LogTrace("Dequeue: Got Item");

await entry.RenewLockAsync();
await OnDequeuedAsync(entry).AnyContext();
ScheduleNextMaintenance(SystemClock.UtcNow.Add(_options.WorkItemTimeout));
await OnDequeuedAsync(entry).AnyContext();

return entry;
}
Expand Down

0 comments on commit a8348a2

Please sign in to comment.