laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.33k stars 10.96k forks source link

Jobs are not retried considering --tries set on worker when fail with ModelNotFoundException #44963

Closed ionutantohi closed 1 year ago

ionutantohi commented 1 year ago

Description:

When a job fails with ModelNotFoundException, the job is not retried automatically considering --tries option set on worker and is added immediately to failed_jobs table.

You might argue that if a model does no longer exists, there is no point in retrying the job because it will fail for the same reason and I agree with that. But the reasons why a model can not be restored are multiple not only because is deleted.

But there are cases when retrying the job will make the job succeed. ie: a worker on a different server that the one from where it was dispatched, and which is listening to a mysql replica and the new record is not yet propagated.

Steps To Reproduce:

  1. $model = Model::create([]);
  2. $model->delete();
  3. dispatch( new SampleJob($model));
  4. php artisan queue:work --tries=3

I expect that SampleJob to be executed 3 times. Currently is executed only once.

driesvints commented 1 year ago

This would seem the expected behavior to me. There's no point in retrying a job if the model cannot be found. You example does not make sense to me.