Why won't Hangfire execute the Child-Batch?

  public void MapEndpoint(IEndpointRouteBuilder app) {

      app.MapGet("/hangfireTest", async (NectaContext context, [FromServices] VendorCatalogHttpClient httpClient) => {
          var parentId = BatchJob.StartNew(batch =>
          {
              batch.Enqueue(HangfireQueue.Debug.Name(), () => Console.WriteLine("STARTED: Parent Job 1"));
              batch.Enqueue(HangfireQueue.Debug.Name(),() => FailingJob()); // Eror!
              batch.Enqueue(HangfireQueue.Debug.Name(), () => Console.WriteLine("STARTED: Parent Job 3"));
          }, description: "Parent-Batch");

          BatchJob.ContinueBatchWith(parentId, batch =>
          {
              batch.Enqueue(HangfireQueue.Debug.Name(), () => Console.WriteLine("STARTED: Child Batch was started!"));
              batch.Enqueue(HangfireQueue.Debug.Name(), () => Console.WriteLine("STARTED: Child Job 2"));
          }, options: BatchContinuationOptions.OnlyOnCompletedState, description:"Child-Batch");

          return Results.Ok("Batch started!");
      })
          .WithName("HangfireTest")
          .WithTags("Dummy")
          .WithOpenApi();
  }

  [AutomaticRetry(Attempts = 0)]
  public void FailingJob() {
      Console.WriteLine("ERROR: This is an error job");
      throw new Exception("Simulated Error in Parent Batch");
  }

the Parent job stays in state “Started”… Items “Not Finished” 1/3
the Child job stays in state “Awaiting”…
even without option BatchContinuationOptions.OnlyOnCompletedState!
I just want to know why.

Hi, could you show me the screenshot of the non-finished background job details page to see all of its state transitions? If it’s in the Failed state, then this is by design – failed state isn’t considered to be the final one and manual intervention to re-queue/delete is required. If you’d like to ignore the exception, consider adding the following attribute to your FailingJob method:

[AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
public void FailingJob()

You can specify the number of automatic retries with the Attempts property. And once their number is exceeded, your background job will be considered as completed and an expiration time will be applied, that will lead to completion of its batch.