It appears that cron jobs in Magento 2 are limited by their settings defined in the cron group they belong to. I'm not sure if this is a bug or a feature.
Alex Gusev already points this out in his answer, but to clarify it a bit more: There are 2 cron groups by default in Magento 2: default
and index
. These are defined in Magento_Indexer/etc/cron_groups.xml
and Magento_Cron/etc/cron_groups.xml
. For example:
<group id="default">
<schedule_generate_every>15</schedule_generate_every>
<schedule_ahead_for>20</schedule_ahead_for>
<schedule_lifetime>15</schedule_lifetime>
<history_cleanup_every>10</history_cleanup_every>
<history_success_lifetime>60</history_success_lifetime>
<history_failure_lifetime>600</history_failure_lifetime>
<use_separate_process>0</use_separate_process>
</group>
These cron group determine the default / global values of every cron job. I'm not sure how it works but according to my own tests you cannot set a cron to run more often per hour than determined in the schedule_generate_every
-setting. So for example, if you have something like this:
<group id="default">
<job name="custom_module" instance="Custom\Module\Cron\DoSomething" method="execute">
<schedule>*/1 * * * *</schedule>
</job>
</group>
Even though you might expect that this cronjob is scheduled every minute, it's global settings limit it to a minimum timeframe of 15 minutes.
To solve this, you can either:
- Edit the setting in the system configuration (Advanced → System → Cron), or:
- Override the global default in your module by adding a
cron_groups.xml
-file of your own (assuming that the client did not already tinker with the configuration settings):
Example config_groups.xml
-file:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/cron_groups.xsd">
<group id="default">
<schedule_generate_every>1</schedule_generate_every>
</group>
</config>
Bug? Feature? Misleading configuration setting? I'm not sure how to call this. You could argue that it's a good thing that you have a global scope that can limit 100+ modules to try to run a cron every minute. On the other hand: If I'm a developer who knows what he's doing, there might be good reasons to run every minute.
If running every minute is mandatory it might also be an idea to add a whole new cron group for your configuration (don't pollute the index
-cron group with non-indexing cron jobs). But that's a matter of architecture and I'll leave that up to you.
<schedule>* * * * *</schedule>
<schedule>* * * * *</schedule>
runs my task every 15 min :(<schedule>* * * * *</schedule>
Probably, there are some Magento 2 configuration settings that prevent launch tasks more, then once in 15 min?cron_schedule
table