I have implemented Hangfire into my project. I now have the need to enqueue multiple jobs that will technically be part of a batch. Company won't buy Pro version of Hangfire that offers batch functionality. Is there a workaround for me to be able to tell when all related jobs are complete so that I can call another function at the very end of each batch?
When Batch A is all done:
When Batch B is all done:
1. Implementing a filter
Batches use the extensibility API available for anyone. You can create a filter that adds a background job id to a some persisted set during the creation phase, sets the "processed" status for an item in the set during the state change process, checks for other pending jobs when a job is processed, and launches a new background job, if it was the last one in the batch.
This is a high level overview of batches. There are a lot of things to be considered, to avoid different race conditions and different scenarios (job re-queue, deletion and so on).
2. Using Hangfire + TPL
Alternatively, you can use Hangfire + TPL instead to perform calculations in parallel, if you have relatively low number of background jobs in a batch. So Batch A is a simple background job, Batch B is its continuation. Methods of Batch A and Batch B use TPL for methods
Task.WaitAll waiting for their completion.