Setting up the job queue daemon¶
Purpose of the queue¶
Jobs launched from the UI or from the CLI are pushed into a queue in order to be processed in background.
One or several daemon processes have to be launched to execute the jobs.
A daemon process can only execute one job at a time. The daemon process cannot execute any other job until the end of the current job. You can launch several daemon processes to execute multiple jobs in parallel.
Also, the daemon processes could be run on several instance of the PIM, using the same MySQL database.
This queue allows horizontal scalability of the PIM. Therefore, you can configure servers dedicated to the execution of the jobs.
The command to launch a daemon is:
$ /path/to/php /path/to/your/pim/bin/console akeneo:batch:job-queue-consumer-daemon --env=prod
You can also run the daemon to execute only one job and then exit. This is useful for development purpose.
$ /path/to/php /path/to/your/pim/bin/console akeneo:batch:job-queue-consumer-daemon --env=prod --run-once
The daemon process writes logs to the standard output.
It’s your responsibility to choose where to write the logs.
For example, to write in the file
$ /path/to/php /path/to/your/pim/bin/console akeneo:batch:job-queue-consumer-daemon --env=prod >/tmp/daemon_logs.log 2>&1
Do note that you should ensure the log rotation as well.
Option #1 - Supervisor¶
It’s strongly recommended to use a Process Control System to launch a daemon in production. This is not useful in development though.
In this documentation, we will describe how to configure the Process Control System supervisor, to run a daemon process. These instructions are valid for Debian 9 and Ubuntu 16.04.
$ apt update $ apt install supervisor
For the other platforms, you can follow the install section of the official documentation.
Create a file in the configuration directory of supervisor
1 2 3 4 5 6 7
[program:akeneo_queue_daemon] command=/path/to/php /path/to/your/pim/bin/console akeneo:batch:job-queue-consumer-daemon --env=prod autostart=false autorestart=true stderr_logfile=/var/log/akeneo_daemon.err.log stdout_logfile=/var/log/akeneo_daemon.out.log user=my_user
my_user should be the same as the user to run PHP-FPM.
Then, bring the changes into effect:
$ supervisorctl reread $ supervisorctl update
Launch the daemon¶
$ supervisorctl start akeneo_queue_daemon
Option #2 - systemd¶
If you prefer, you can use
systemd, which will also allow for multiple daemons to run at the same time,
to have logs management and auto restart in case of failure.
1 2 3 4 5 6 7 8 9 10 11 12 13
[Unit] Description=Akeneo PIM Job Queue Service (#%i) After=apache2.service [Service] Type=simple User=akeneo WorkingDirectory=/path/to/akeneo/ ExecStart=/path/to/akeneo/bin/console akeneo:batch:job-queue-consumer-daemon --env=prod Restart=always [Install] WantedBy=multi-user.target
Manage the services¶
1 2 3 4 5 6 7 8 9 10 11
# use * if you want the operation to apply on all services. systemctl [start|stop|restart|status] pim_job_queue@* # start a pim job queue systemctl start pim_job_queue@1 # start another one systemctl start pim_job_queue@2 # check the logs in real time for daemon #2 journalctl --unit=pim_job_queue@2 -f
Manage services by non-root users¶
sytemctl is not useable by non-privileged users, if you want to allow a user
apt install sudo visudo
You can then type in the following lines, depending on what commands you want to allow.
1 2 3 4 5
akeneo ALL=(root) NOPASSWD: /bin/systemctl start pim_job_queue@* akeneo ALL=(root) NOPASSWD: /bin/systemctl stop pim_job_queue@* akeneo ALL=(root) NOPASSWD: /bin/systemctl status pim_job_queue@* akeneo ALL=(root) NOPASSWD: /bin/systemctl restart pim_job_queue@* akeneo ALL=(root) NOPASSWD: /bin/systemctl reload pim_job_queue@*
Found a typo or a hole in the documentation and feel like contributing?
Join us on Github!