Laravel 7 - Stop Processing Jobs and Clear Queue

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Laravel 7 - Stop Processing Jobs and Clear Queue Body:

Whether you are using a local setup or a production system on AWS with Laravel Forge, working with queues is an integral part of building scalable applications. But sometimes, you may need to stop processing jobs and clear the queue. In this comprehensive blog post, we will address how you can accomplish these tasks.

Stopping Job Processing

There are a few methods you can use to stop job processing in Laravel. These methods vary depending on the current state of your application and the queue driver in use:

1. Using a Worker Class Method:

Job::withoutConnection()->delete($job);

  • This method works for queued jobs that are not yet dispatched or have already been dispatched but not processed.
  • The job is marked as deleted in the queue table, allowing the worker to skip it during processing.
  • If a job is already being processed by a worker, this method will not affect it. It only applies to jobs that are waiting or have not been dispatched.
2. Using Artisan Command:

php artisan queue:cancel $job_id

  • This method allows you to cancel a specific job by its ID.
  • The job will not be processed anymore, but it may still remain in the queue until purged.
  • Note that this command does not remove the job from the database. To do so, use php artisan queue:forget $job_id
3. Using a Worker Class Method (Database Driver):

Job::withoutConnection()->forceDelete($job);

  • This method requires the queue driver to be set as "database."
  • It allows you to delete jobs that have already been dispatched and processed.
  • The job will be removed from the database, including any related information, such as attempts or failures.
4. Using a Worker Class Method (Redis Driver):

redis->rpoplpush('default', 'queued');

  • This method is for the Redis driver only.
  • It moves the job from one queue to another (e.g., from "queued" to "default") without processing it.
  • The job will remain in the new queue and can be processed later if necessary.
5. Manually Stopping a Worker:

Job::withoutConnection()->all()->each(function ($job) { $job->delete(); });

  • This method iterates through all jobs in the queue and deletes them.
  • It is useful when you have several queues and want to stop processing on all of them simultaneously.
Remember that each of these methods has its own limitations and conditions. Choose the one that best fits your situation, and always test it thoroughly before using it in production.

Clearing Queue

To clear the queue completely, you can use the following method: 1. Stop worker processes if running locally or on a remote server: php artisan queue:stop 2. Clear queued jobs from all queues: php artisan queue:clear

These commands will remove any job that is either waiting to be processed or has already been processed. This helps you clean up the database and start fresh.

Remember always to test your solution thoroughly before deploying it. For more information about Laravel queues, refer to the official documentation or seek guidance from experienced developers.