How to block parent of nested Hangfire jobs until children are finished?


#1

I currently have nested Background Jobs. Something like:

BackgroundJob.Enqueue(x => x.CalculateAll(myId));

public void CalculateAll(int id)
{
   var myList = _repo.GetMyList(id);
   foreach (var item in myList)
   BackgroundJob.Enqueue(x => x.DoDiffCalculation(item.id));
}

In this example, the inner Enqueue will block in Hangfire until the DoDiffCalculation is complete, but the outer Enqueue succeeds immediately with success in Hangfire, even though the child jobs have not completed. How do I get the outer job to keep running until all the child jobs are completed?