Magento 2.3.2 CE and Cron jobs, flock and RabbitMQ

by Anton Boritskiy   Last Updated August 14, 2019 00:09 AM - source

Last few days I was chasing an interesting bug in production system running Magento 2.3.2 CE Where as per community recommendation I run cron jobs like this

flock --timeout=0 /run/lock/magento_system_cron.lock  /usr/bin/php /var/www/html/bin/magento cron:run

After few executions of cron task it is suddenly gets locked and flock never releases this lock. The only way to release it is to either remove the lock file (which is incorrect, don't do it) or figure out related process IDs and kill them. One can figure out process IDs like this:

fuser -u /run/lock/magento_system_cron.lock

Once you know process IDs - do something like ps aux | grep <process-id-from-fuser-command>

Well, when you see processes that are involved there you would probably understand why it gets locked forever. Those processes are message consumers and they are supposed to sit and wait (they are actually blocked and effectively sleeping) till they receive a message via the message-queue mechanism and then process them.

Magento documentation is somewhat vague on this:

At the same time I noticed that cron jobs get blocked once I see this in logs:

main.INFO: Consumer "async.operations.all" skipped as required connection "amqp" is not configured. Unknown connection name amqp []

And googling for that was always leading me to the tip to disable the cron configuration for those message consumers, which didn't sound right to me:

// app/etc/env.php
// ...
'cron_consumers_runner' => array(
    'cron_run' => false,
    'max_messages' => 1000,
    'consumers' => array(

See this for instance:

Related questions:

Somehow it became clear to me that something is not right with that message-queue setup as well with cron configuration. So I was looking through Magento docs multiple times and were not finding there what is supposed to consume messages that magento pushes into rabbitMQ, see this for example:

The question that I was asking myself all the time: "What am I missing here?" and "What is a recommended setup here?"

Answers 1

So far I came to the following conclusions and possible answers to the question:

  1. Remove flock, leave the rest of configuration as per default and hope for the best.
  2. Keep flock, disable starting of message consumers per cron and manage that on per-consumer way using other tools

    1. use separate cron jobs with per-consumer flock
    2. use as per Magento docs recommendation

In either case it is a good idea to have RabbitMQ installed and configured for your Magento, cause it will be used either way.

You can get the list of all consumers you need to manage if you execute:

bin/magento queue:consumers:list
Anton Boritskiy
Anton Boritskiy
August 13, 2019 23:30 PM

Related Questions

Magento 2 independent cron job queue

Updated March 01, 2019 13:09 PM

Magento Email-Queue not working

Updated November 21, 2018 23:09 PM

How to Use RabbitMq in Magento2 CE

Updated March 03, 2018 18:09 PM

Send all emails with cron/queue

Updated October 23, 2018 06:09 AM