Laravel Queues in Action (2nd edition) is now available!

Removing Jobs of a Specific Type from a Laravel Queue

Updated: Sep 27, 2022 — 1 min Read#queues

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()

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.

Hey! 👋 If you find this content useful, consider sponsoring me on GitHub.

You can also follow me on Twitter, I regularly post about all things Laravel including my latest video tutorials and blog posts.

By Mohamed Said

Hello! I'm a former Laravel core team member & VP of Engineering at Foodics. In this publication, I share everything I know about Laravel's core, packages, and tools.

You can find me on Twitter and Github.

This site was built using Wink. Follow the RSS Feed.