I am using Magento CE 2.0.0.
I set up cron job for my custom task but I could not make it run every 15 minutes. So can someone provide detailed explanation about how to correctly set up schedule?
- Firstly, there is a configuration for cron in admin:
This parameters are for generating "cron_schedule" table in database. How these parameters affect on my task scheduling (I'm using group "default")?
- On server I must set up task in crontab to run magento cron:run. So in my case it (crontab -l):
*/15 * * * * /usr/bin/php /srv/www/my_directory/bin/magento cron:run
In magento devdocs there is the note:
What does it mean? Do I have to include my command twice in crontab? For example:
*/15 * * * * /usr/bin/php /srv/www/my_directory/bin/magento cron:run; /usr/bin/php /srv/www/my_directory/bin/magento cron:run
- Lastly, there is a cron job configuration in Magento 2 crontab.xml:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd"> <group id="default"> <job name="my_custom_job" instance="My\Module\Cron\MyCustomJob" method="execute"> <schedule>*/15 * * * *</schedule> </job> </group> </config>
I set it to run every 15 minutes.
So how to put all these things together? I want to run my custom task every 15 minutes.
Here is the debug.log:
> [2016-09-23 12:00:03] main.DEBUG: MyCustomTask {"is_exception":false} []
> [2016-09-23 12:15:03] main.DEBUG: MyCustomTask {"is_exception":false} []
> [2016-09-23 13:00:03] main.DEBUG: MyCustomTask {"is_exception":false} []
> [2016-09-23 13:30:03] main.DEBUG: MyCustomTask {"is_exception":false} []
> [2016-09-23 14:45:03] main.DEBUG: MyCustomTask {"is_exception":false} []
> [2016-09-23 16:00:03] main.DEBUG: MyCustomTask {"is_exception":false} []
> [2016-09-23 16:45:03] main.DEBUG: MyCustomTask {"is_exception":false} []