Skip to content

[13.x] Wrap retrying job exceptions in JobRetryingException #59271

Open
jackbayliss wants to merge 1 commit intolaravel:13.xfrom
jackbayliss:13.X-job-retrying-exception
Open

[13.x] Wrap retrying job exceptions in JobRetryingException #59271
jackbayliss wants to merge 1 commit intolaravel:13.xfrom
jackbayliss:13.X-job-retrying-exception

Conversation

@jackbayliss
Copy link
Contributor

@jackbayliss jackbayliss commented Mar 18, 2026

I regularly see exceptions and think a job has failed, and go to put the job back onto the queue, to realise its not actually failed hard, its just been retried and is already sorted

This PR wraps exceptions in a JobRetryingException when a job is released back to the queue for retry, allowing exception handlers and us to tell the difference between exceptions that caused failure vs. ones where the job will be retried.

Open to renaming it or something different I'm just one man, but trying to make it more obvious as it's hard to tell if it's something we need to act or or not atm.

This is very helpful with tracking tools, Sentry, Mezmo etc.

This is the current trace I get where I need to decide if its a real failure that I may need to manually pop back onto the queue or not :

Details
{
"message": "SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction",
"trace": [
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:609",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:827",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:794",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:597",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:4289",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1291",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:23",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2540",
"/srv/app/some-app-prd/htdocs/app/Jobs/AJob.php:27",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Container/Util.php:43",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:96",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:35",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php:799",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:129",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:137",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php:133",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:136",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:137",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:129",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:70",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:102",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:485",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:435",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:201",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:148",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:131",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Container/Util.php:43",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:96",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:35",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php:799",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Console/Command.php:211",
"/srv/app/some-app-prd/htdocs/vendor/symfony/console/Command/Command.php:341",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Console/Command.php:180",
"/srv/app/some-app-prd/htdocs/vendor/symfony/console/Application.php:1117",
"/srv/app/some-app-prd/htdocs/vendor/symfony/console/Application.php:356",
"/srv/app/some-app-prd/htdocs/vendor/symfony/console/Application.php:195",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:198",
"/srv/app/some-app-prd/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:1235",
"/srv/app/some-app-prd/htdocs/artisan:14"
]

@github-actions
Copy link

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@jackbayliss jackbayliss marked this pull request as ready for review March 18, 2026 13:34
@taylorotwell
Copy link
Member

Hmm, interesting 🤔 so you try to re-queue the job before you see it show up definitively in the failed jobs table?

@jackbayliss
Copy link
Contributor Author

jackbayliss commented Mar 18, 2026

@taylorotwell I get an alert for any exceptions, so cause this is via a job I assume I need to retry the job, (as it's not clear if it's actually failed or retried right) so I check the DB, to then realise it was already retried automatically, so this just makes it obvious I don't need to do anything 😆 and to anyone else getting the alerts.

TLDR is basically its not clear if I/we need to act or not just from the exception so this makes it clear. some jobs are high priority etc, so should be retried ASAP basically. It's also useful for logging tools so we can figure out the flow easily

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants