BatchJob continuations

Hi,

I’m using Hangfire Batches and this is what I want to achieve. I have a job that generates a BatchJob:

 BatchJob.StartNew(x =>
  {
      foreach (var offer in offers)
      {
          x.ContinueJobWith<TestJob>(parentJobID, j => j.Execute(x.BatchId));
      }
  }, $"Batch test");

Then, I want to do something when the batch ends:

BatchJob.ContinueBatchWith(batchId, x => {
    x.ContinueJobWith(parentJobId, () => End(null)); 
    }
);

But here is the problem. TestJob.Execute has a continueJobWith inside. From what I see, the batch won’t wait that job because it is not linked to the batch so…will be a way to solve it just doing this inside TestJob.Execute code?:

BatchJob.Attach(batchId, x =>
{
    x.ContinueJobWith(parentJobID, () => NextStep(null, batchId));
});

This way a job will be attached to the batch before the current job execution ends so it won’t be marked as Finished and it will wait till NextStep execution to finish to continueBatchWith the EndStep.

Is that correct? I think it’s working but want to guarantee it.

Thanks!