Laravel job is retried even when option tries is set to 1

Tram Ho

Error like the title, you can see at https://github.com/laravel/framework/issues/15696 And once again the laravel contributors said this was feature =)) https://github.com/ laravel / framework / issues / 15696 # issuecomment-250935907

In short, laravel will re-run the job after the job timeout no matter how many times you try to time the job. Read the laravel code you will see. Illuminate Queue Worker :: markJobAsFailedIfAlreadyExceedsMaxAttempts

How to fix:

1. Set the option retry_after and restart queue every <retry_after time

Example: You set the job retry_after to 3600 seconds and restart queue every 2000 seconds.

2. Split job straight into multiple jobs.

If your job is doing a split job, create child jobs and dispatch child jobs in the parent job to avoid timeout.

3. Create 1 class extends from Illuminate Queue Worker class and override funtion markJobAsFailedIfAlreadyExceedsMaxAttempts

Simply delete the 3 lines of the other debt.

And don’t forget to write a console command for the new worker class. Refer to the code in the vendor / laravel / framework / src / Illuminate / Queue / Console / WorkCommand.php file. Whoever finished writing, share it for me, I have not yet written =))

Share the news now

Source : Viblo