[14.x] Mark batches allowing failures as finished once all jobs have run

Merged
PA
14d ago
+57-2

Fixes #61835. Resubmitting #62207 against 14.x, since it was closed on 13.x as a possible breaking change for a patch release.

A batch that allows failures runs its finally() callbacks once every job has either succeeded or failed, but finished_at is only set when every job succeeded. So as soon as one job fails, the batch never reports finished(), and queue:prune-batches only removes it through --unfinished.

This sets finished_at at the same point finally() runs, so finally() now receives a finished batch.

Unchanged on purpose:

  • pending_jobs / failed_jobs, so queue:retry-batch still works. A successful retry goes through the normal success path and updates finished_at again.
  • then() still only runs when every job succeeded.
  • BatchFinished is still only dispatched on full success, so existing listeners don't start firing for failed batches.

Upgrade note: for batches using allowFailures(), finished() now returns true once every job has run, even if some failed. Code that used finished() to mean "every job succeeded" should check $batch->pendingJobs === 0 or ! $batch->hasFailures() instead.