Specifying Cron group options

You may declare a new group and specify its configuration options (all of which run in store view scope) via the cron_groups.xml file, located in:

<your component base dir>/<vendorname>/module-<name>/etc/cron_groups.xml

Below is an example of the cron_groups.xml file:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/cron_groups.xsd">
    <group id="<group_name>">
        <schedule_generate_every>1</schedule_generate_every>
        <schedule_ahead_for>4</schedule_ahead_for>
        <schedule_lifetime>2</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>1</use_separate_process>
    </group>
</config>

Where:

OptionDescription
schedule_generate_everyFrequency (in minutes) that schedules are written to the cron_schedule table.
schedule_ahead_forTime (in minutes) in advance that schedules are written to the cron_schedule table.
schedule_lifetimeWindow of time (in minutes) that a cron job must start or the cron job is considered missed (“too late” to run).
history_cleanup_everyTime (in minutes) that cron history is kept in the database.
history_success_lifetimeTime (in minutes) that the record of successfully completed cron jobs is kept in the database.
history_failure_lifetimeTime (in minutes) that the record of failed cron jobs is kept in the database.
use_separate_processRun this cron group’s jobs in a separate php process

Disable a cron job

Cron jobs do not have a disable feature like we have for observers. However, a cron job can be disabled by using the following technique: schedule a time that contains a date which will never happen.

For example, disable the visitor_clean cron job which defined in Magento_Customer module:

...
<group id="default">
    <job name="visitor_clean" instance="Magento\Customer\Model\Visitor" method="clean">
        <schedule>0 0 * * *</schedule>
    </job>
</group>
...

To disable the visitor_clean cron job, create a custom module and rewrite the visitor_clean cron job schedule:

...
<group id="default">
    <job name="visitor_clean" instance="Magento\Customer\Model\Visitor" method="clean">
        <schedule>0 0 30 2 *</schedule>
    </job>
</group>
...

Now, the visitor_clean cron job has been set to run at 00:00 on the 30th of February - at the date which will never occur.

Previous pageCron jobs and groups
Next pageConfigure a custom cron job

Commerce