Skip to content

Commit

Permalink
Fix not decrementing number of running queue tasks on fail (#192)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Temešinko <[email protected]>
  • Loading branch information
temesinko and Jan Temešinko authored Oct 5, 2020
1 parent 612204c commit 1df1269
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 5 additions & 5 deletions Src/Coravel/Queuing/Queue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,18 @@ private async Task InvokeTask(ActionOrAsyncFunc task)

await task.Invoke();

Interlocked.Decrement(ref this._tasksRunningCount);
this._logger?.LogInformation("Queued task finished...");
await this.TryDispatchEvent(new QueueTaskCompleted(task.Guid));
}
catch (Exception e)
{
await this.TryDispatchEvent(new DequeuedTaskFailed(task));

if (this._errorHandler != null)
{
this._errorHandler(e);
}
_errorHandler?.Invoke(e);
}
finally
{
Interlocked.Decrement(ref this._tasksRunningCount);
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions Src/UnitTests/CoravelUnitTests/Queuing/QueueMetricTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public async Task TestQueueHasCorrectNumberOfJobsRunning()
Queue queue = new Queue(null, new DispatcherStub());

queue.QueueAsyncTask(() => Task.Delay(200));
queue.QueueAsyncTask(() => Task.Delay(200));
queue.QueueAsyncTask(async () =>
{
await Task.Delay(200);
throw new Exception("Test exception");
});
queue.QueueAsyncTask(() => Task.Delay(200));

Assert.Equal(3, queue.GetMetrics().WaitingCount());
Expand All @@ -45,7 +49,10 @@ public async Task TestQueueHasCorrectNumberOfJobsRunning()
Assert.Equal(3, metrics.RunningCount());

await consumingTask;
}

metrics = queue.GetMetrics();
Assert.Equal(0, metrics.RunningCount());
}

[Fact]
public async Task TestAllGuidMethods()
Expand Down

0 comments on commit 1df1269

Please sign in to comment.