Cancelling a batch that contains job continuations

We have some logic that requires certain jobs in a specific, for example, attempting to purchase a set of items in the order they were created, but with isolation, so if item A fails, item B is still attempted.

To do this we use job continuations, so purchase job A has a continuation to purchase job B, marked as continuing on any finished state.

Additionally this is done as a large batch of purchases for a subset of users, we create an empty batch and attach the jobs into the batch so they can begin executing immediately, and we can attach a continuation onto the batch to generate a final overall report once they are complete.

We have noticed if the batch is cancelled, jobs without continuations move to the deleted state, but the continuation jobs are stuck in the pending tab of the batch dashboard, all in the awaiting state.

This is on Hangfire 1.7.9 with Hangfire.Pro 2.2.1, using SQL Server as the storage backend.

Also worth noting we can manually enqueue the jobs with the awaiting state and they immediately go into deleted state.

Thanks for reporting this problem, I’ve fixed filter execution order and just released Hangfire.Pro 2.2.3. The problem was caused by wrong execution order of filters, and filter responsible for running or canceling continuations was running before realizing that background job should be canceled.

Just got some time to test this new version and it works, no more jobs stuck awaiting on a cancelled batch, thank you, great support :smiley:

1 Like