[10.x] Add resume method to batched jobs as an option #49198
Closed
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.
With the new Job Chain/Batching feature (#48633), I am moving my custom implementation over to the "Laravel Way".
Currently, you can do the following with a Job Batch:
Without being inside of a Chain, this was good enough for my use case because I would allow failures, but then only move to the next 'step' after all failed jobs were remediated. Now that I can take advantage of the Job Chain with Batches inside, I need to be able to cancel a Batch on failure....fix the issue, and restart the jobs in the batch that failed.
My Use Case:
Batch 1 has 100 jobs. All 100 jobs must be completed(not failed) before going to Batch 2.
Batch 2 has 30 jobs. All 30 jobs are dependent upon the data received in the Batch 1 jobs.
What I Am Currently Doing:
Batch 1 created a unique lock based on an ID. Once Batch 1 completed, an event was sent to remove the 'lock'
Batch 2 would check if that lock still existed. If so, return the job to the queue and try again.
I need to be able to have a job inside of Batch 1 fail and cancel the batch(Therefore, cancelling the Chain it is in). After I remedy the failure, I need to be able to run
queue:retry-batch {id}
.The problem: Retrying the batch does not "un-cancel" the batch, meaning that inside of the job when checking if cancelled, it doesn't perform the actions.
The solution: Retrying the batch has an option to
--resume
which "un-cancels" the batch, allowing the business logic to be ran.Scenario(End Goal):
Job(1)
successfully runs.Job(2)
fails and cancels the batch.// The chain has now stopped.
// Fix failure reason manually and run
queue:retry-batch {id} --resume
Job(2)
successfully runs now.Job(3)
successfully runs.$batch2
now runs