Running Cron Jobs in Magento 2

Running Cron Jobs in Magento 2 can be very useful to automate repetitive tasks. A cron is a Linux utility which schedules a command or script on your server to run automatically at a specified time and date.

Setting up crontab in our machine

First of all, to run Cron Jobs in Magento 2 you have to set up the Magento 2 cron commands in your crontab service.

joki@jokiruiz:~$ sudo crontab -u www-data -e

If your apache2 or nginx user is not www-data change it, and insert in your cron the following lines:

Adding a custom cron to our module.

Here you have to specify a group_id (can be a default group or a custom group), and the job name. Inside the job, you have to set the instance of the class and the method you want to execute, and finally the schedule in crontab format.

Source

I hope you enjoyed the post about Running Cron Jobs in Magento 2, and helps you with your cron jobs setup. Do you have any tricks to share? Please comment!

Magento 2 rules ! 🙂

share

The Author

Joaquín Ruiz

Computer Engineer, Senior Full-Stack Developer and Lead Developre.
Joki has more than 8 years of experience working with multiple PHP frameworks.
He knows Magento, WordPress, Laravel, Yii.. like the back of his hand ;)