cancel
Showing results for 
Search instead for 
Did you mean: 

Cron Jobs and Cron Group

Cron Jobs and Cron Group

Hi Guys,

I am a newbie in Magento and I want to understand the Cron Jobs, please.

If I want to create new cron job inside default cron group, but I want to set different schedules time for it, is it possible or I have to create custom cron group.

What is the difference between crontab.xml file and cron_groups.xml file?

In crontab.xml file I see each cron job has its own schedules but in cron_groups.xml file it seems the schedules are general for all cron jobs in the group, which one to use?

 

crontab.xml file:

<config>
<group id="default">
    <job name="<job_1_name>" instance="<classpath>" method="<method_name>">
        <schedule>* * * * *</schedule>
    </job>
    <job name="<job_2_name>" instance="<classpath>" method="<method_name>">
        <schedule>* * * * *</schedule>
    </job>
</group>
<group id="index">
    <job name="<job_3_name>" instance="<classpath>" method="<method_name>">
        <schedule>* * * * *</schedule>
    </job>
    <job name="<job_4_name>" instance="<classpath>" method="<method_name>">
        <schedule>* * * * *</schedule>
    </job>
</group>

cron_groups.xml file:

<config>
<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>

I do not understand what is the meaning of sconnector and ddg_automation cron group

6 REPLIES 6

Re: Cron Jobs and Cron Group

Hi @mustafa_abdel a 

 

I understand the question you have asked !

 

Basically cron jobs (crontab) and cron group have difference but both are used for running crons in any Magento project.

 

If we talk about crontab - If your custom module needs to schedule tasks periodically, you must set up a crontab for that module. A crontab is a cron job’s configuration.

 

If we talk about cron group - A cron group is a logical group that enables you to easily run cron for more than one process at a time. Most Magento modules use the default cron group; some modules use the index group.

 

So if you are looking to generate cron job for your custom module periodically then i would suggest you to create crontab and add schedule time on the same. 

 

To know more and get the exact idea, i would suggest you to refer this doc - https://devdocs.magento.com/guides/v2.3/config-guide/cron/custom-cron-ref.html 

 

Let me know if i you want to know more on this, will be happy to assist you further

 

Hope it helps !

 

 

if issue solved,Click Kudos & Accept as Solution

Re: Cron Jobs and Cron Group

Hello @mustafa_abdel a 

 

You can optionally set up a custom group, using this among other things enables you to run cron jobs defined in that group independently of other cron jobs. Simple meaning, you can define multiple cron jobs to run all together independently using a custom cron group. 

 

You can follow below shared post to understand cron job and cron group:

https://manishmittal.com/magento-2-set-up-a-custom-cron-job-and-cron-group/

 

 

Manish Mittal
https://www.manishmittal.com/

Re: Cron Jobs and Cron Group

Thank you @Manthan Dave , and @Manish Mittal 

 

But lets take an real example and try to apply it to get fully understand for Cron.

Suppose I have 2 Cron Jobs every one should run in different schedule, so i need to create 2 different Cron Group

 

That is the configuration that I thought for Cron and tell me if that is right or not

 

For first Cron Job that need to run every 33 min and start at 5 October 2020:

<config>
<group id="<group_name>">
    <schedule_generate_every>33</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>

    <job name="<job_name>" instance="<classpath>" method=" 
    <method_name>">
        <schedule>0 0 5 10 2020</schedule>
    </job>
</group>

For second Cron Job that need to run every 15 min and start at 10 October 2020:

<group id="<group_name>">
    <schedule_generate_every>15</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>

    <job name="<job_name>" instance="<classpath>" method=" 
    <method_name>">
        <schedule>0 0 10 10 2020</schedule>
    </job>
</group>

 

Re: Cron Jobs and Cron Group

@mustafa_abdel a 

 

It seems you have merged both cron job and cron groups. If both are running seperatly you dont need to configure cron group. It is optional to configure if only cron is running. Cron group used to group up 2 or more cron for same time to run these cron.

 

for schedule timing format please follow below shared link:

http://www.nncron.ru/help/EN/working/cron-format.htm

Manish Mittal
https://www.manishmittal.com/

Re: Cron Jobs and Cron Group

@Manish Mittal @Manthan Dave 

 

yes, but if I want to make just one cron job, where to set the Frequency of running job?

schedule here is used for Start Time

<job name="<job_4_name>" instance="<classpath>" method="<method_name>">
        <schedule>* * * * *</schedule> 
    </job>

 

 

 

Re: Cron Jobs and Cron Group

@mustafa_abdel a 

 

You have to define separate frequency for each cron job. What you required that can be fulfil by cron group and that also only when you have same frequency or time for those cron else you have to define separate for all cron jobs. 

Manish Mittal
https://www.manishmittal.com/