A few days ago, a pending pull-request was merged by mistake. This caused a certain job to be pushed to the queue for over 100,000 times. This job had an incomplete implementation and was reverted once the team noticed it was pushed.
Now we have a queue that has over 100,000 jobs that resolve a class that doesn't exist, because the PR was reverted. Workers keep picking those jobs up and erroring because they can't resolve the class the jobs belong to.
How can we delete just instances of this job from the queue without having to purge the entire queue? I've seen this question a few times in GitHub issues and the Laracasts forum, and I always wanted to write a short post about the solution. Which is rather simple.
First, you'll need to create a an empty job with exactly the same name of the removed job class and the same namespace. Inside the job handle
or __invoke
method, just return immediately:
public function handle()
{
return;
}
Now when you deploy your code, workers will pick those jobs up and process them successfully and immediately. After a while, those jobs will be cleaned off the queue.