Laravel Artisan Queue Command: The queue:work Command

December 7, 2016 —John Koster

The queue:work command is similar to the queue:listen command, but with a few differences. This command can be used to process only the first job on the queue in a "one off" fashion like so:

1# Process the first job using the `--once` option.
2php artisan queue:work --once

The following table lists and describes each of the various options the queue:work command defines (notice they are similar to the queue:listen command):

Argument/Option Description Default
connection The name of the connection. This argument assumes the value of the QUEUE_DRIVER environment variable. If the QUEUE_DRIVER environment variable has not been set, it will default to sync.
--queue The queue to listen on. Also used to set queue priority. default
--memory The memory limit, in megabytes. 128
--timeout The number of seconds a job can run before timing out. 60
--sleep The number of seconds to wait before checking the queue for jobs. 3
--tries The number of times to attempt a job before logging it as failed. 0
--delay The amount of time, in seconds, to delay failed jobs. 0
--force Forces the worker to run even in maintenance mode. The default behavior is to not process jobs when in maintenance mode.
--once Only processes the next job on the queue. The default behavior is to run the queue worker as a daemon, and not process the jobs one at a time.

When running in daemon mode (using the --daemon flag, it is important to note that each daemon has to be restarted when pushing code changes. See the section on the queue:restart command for information on how to do this).

The following examples demonstrate the various ways to call the queue:work command (see the section on queue:listen for more examples):

1# Run the worker in daemon mode (default)
2php artisan queue:work
3 
4# Force the worker to run in maintenance mode.
5php artisan queue:work --force
6 
7# Combine daemon mode and the ability to run
8# while in maintenance mode.
9php artisan queue:work --force
10 
11# Specify the number of seconds to delay the restart
12# of failed jobs to 30 seconds.
13php artisan queue:work --delay=30

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.