Disclaimer: This is a user generated content submitted by a member of the WriteUpCafe Community. The views and writings here reflect that of the author and not of WriteUpCafe. If you have any complaints regarding this post kindly report it to us.

Setup Cron job by configuration allows you to schedule Cron dynamically. In a few cases, developers make use of static time expressions to set Cron Job in a custom module. In that case, whenever you make any changes to the time expression, you must have to change the crontab.xml file.

In order to avoid this issue, we have come up with programmatic solutions by which you can quickly make any changes to the time expression. In case you missed our previous article on How to change Magento 2 configuration using Command Line Interface, check it out here.

If you follow the steps below from the admin configuration, you can easily make any changes to the time expression. Therefore, you don’t need to make the changes to the crontab.xml file.

Let’s get started on how to set up Custom Cron Job by configuration in Magento 2.

Steps to set up Custom Cron Job in Magento 2:

  • Step 1: Create crontab.xml file

    First of all, you need to go to the path: appcodeMageSparkCrontimeetccrontab.xml

    And add the contents in crontab.xml file.

    <?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 instance="MageSparkCrontimeCronCronfile" method="execute" name="my_cron_job">
                <config_path>crontab/default/jobs/my_cron_job/schedule/cron_expr</config_path>
            </job>
        </group>
    </config>

Get the more Code Visit:- https://www.magespark.com/blog/post/how-to-set-up-custom-cron-job-in-magento-2?utm_source=writeupcafe&utm_medium=article&utm_campaign=july-2022

https://www.magespark.com/
Do you like Magespark's articles? Follow on social!

Login

Welcome to WriteUpCafe Community

Join our community to engage with fellow bloggers and increase the visibility of your blog.
Join WriteUpCafe