[12.x] :feat: Add Job Failure Callbacks to Batch #55916
Open
+57
−35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Functional Enhancement
The functional change is in
PendingBatch::allowFailures()
, which now accepts:This allows the registration of callbacks that will be executed when a job fails, providing more granular control over failure handling in batch processing. The
Batch
class has been updated with corresponding methods to handle these new failure callbacks.Of course,
$batch->allowFailures()
and$batch->allowFailures($boolean)
still work as before.Additional Changes
invokeCallbacks
method in the Batch classNotes
$batch->failure($callback)
instead of dual-purposing$batch->allowFailures()
, but went with the latter since the former would require either a call toallowFailures()
anyway, setting this option implicitly in thefailure()
implementation, or reworking the logic ofallowsFailures()
to also return true when failure callbacks are present. I'm open to reworking this in any of those directions.JobContext
object that would be passed to the callback providing more job specific detail, making this potentially more useful.