2

I am using Laravel queues in my application, I have following configuration,

.env:

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=database
SESSION_DRIVER=file

config/queue.config

'default' => env('QUEUE_CONNECTION', 'sync'),


'connections' => [

    'sync' => [
        'driver' => 'sync',
    ],

    'database' => [
        'driver' => 'database',
        'table' => 'jobs',
        'queue' => 'default',
        'retry_after' => 90,
    ]
]

I have setup supervisor and it has following configuration

/etc/supervisor/conf.d/laravel_queue.sh

[program:laravel_queue]
process_name=%(program_name)s_%(process_num)02d
command=php /usr/local/bin/run_queue.sh
startsecs = 0
autostart=true
autorestart=true
user=root
redirect_stderr=true
stderr_logfile=/var/log/laraqueue.err.log
stdout_logfile=/var/log/laraqueue.out.log

/usr/local/bin/run_queue.sh

php /var/www/myproject/artisan queue:work --tries=1

Problem:

When I set QUEUE_CONNECTION=sync it works fine, but jobs are executed synchronously. I want them to execute asynchronously. So when I set QUEUE_CONNECTION=database my jobs are not executed at all and I can see them sitting in my jobs table.

I have also observed that when I run php artisan queue:work directly from my project's directory it works as expected, that is jobs are executed asynchronously.

Any help in this regard is much appreciated.

1
  • What is /usr/local/bin/run_queue.sh? Commented Aug 10, 2019 at 3:12

2 Answers 2

2

From the Queue section of the Laravel docs (5.4):

Configuring Supervisor

Supervisor configuration files are typically stored in the /etc/supervisor/conf.d directory. Within this directory, you may create any number of configuration files that instruct supervisor how your processes should be monitored. For example, let's create a laravel-worker.conf file that starts and monitors a queue:work process:

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/forge/app.com/artisan queue:work sqs --sleep=3 --tries=3
autostart=true
autorestart=true
user=forge
numprocs=8
redirect_stderr=true
stdout_logfile=/home/forge/app.com/worker.log

In this example, the numprocs directive will instruct Supervisor to run 8 queue:work processes and monitor all of them, automatically restarting them if they fail. Of course, you should change the queue:work sqs portion of the command directive to reflect your desired queue connection.

Starting Supervisor

Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:

sudo supervisorctl reread

sudo supervisorctl update

sudo supervisorctl start laravel-worker:*

For more information on Supervisor, consult the Supervisor documentation.

A brief explanation about this commands (source):

  • reread - Reread supervisor configuration. Do not update or restart the running services.
  • update - Restart service(s) whose configuration has changed. Usually run after 'reread'.
  • reload - Reread supervisor configuration, reload supervisord and supervisorctl, restart services that were started.
  • restart - Restart service(s)

As an addition, this article can throw some lights to your issue. Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

1

I am not sure about the Laravel 5.8 but I set up the followings for Laravel 5.3

// Define the queue driver
php /var/www/myproject/artisan queue:work database --tries=1

and defined the numprocs=1 in the supervisord configuration file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.