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

Closed
PA
14d ago
+57-2

Fixes #61835.

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.

The existing test that asserted these batches never finish is updated, and a new one covers a failure followed by a successful last job and a retry.