We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Laravel's queuing system is simply unique. It has so much power and functionality! When your application grows, you will
soon start using a queue, and your queue will also get more and more jobs. It can happen that a model is deleted after
queuing a job. If this happens, the job will fail and throw a ModelNotFoundException
.
To prevent the job from ending up as a failed job, you can add the $deleteWhenMissingModels
property to your job
class. This also works for job chains. If the job has this property and fails, the rest of the chain will be stopped.
There will be no failed job logged.
<?php
class ActivateCard implements ShouldQueue
{
public $deleteWhenMissingModels = true;
private $card;
public function __construct(Card $card)
{
$this->card = $card;
}
public function handle()
{
// Do your thing here
}
}
Keep in mind that you're careful with this approach. Let's say you have a system where you handle payments. In that case, you probably do want to know if something went wrong with generating a bill or managing some invoice.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.