Can anyone explain the methods to doing this job done?

Thank you in advance.


First you need to create your cron in Cron directory



    namespace Vendor\Module\Cron;
    class Mycron
        protected $logger;
        public function __construct(
            \Psr\Log\LoggerInterface $loggerInterface
        ) {
            $this->logger = $loggerInterface;
        public function execute() {
            //Code here

then create cron_groups.xml in app/code/Vendor/Module/etc/cron_groups.xml

<?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="vendor_module_cron_group">

This will add entry in admin

Now for scheduling create crontab.xml in app/code/Vendor/Module/etc/crontab.xml. Schedule it according to your need

<?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="vendor_module_cron_group">
        <job name="vendor_module_cronjob_mycron" instance="Vendor\Module\Cron\Mycron" method="execute">
            <schedule>*/5 * * * *</schedule>

This will run your cron every 5 min. your magento cron must be configured on your server or you can run manually by running php bin/magento cron:run (run twice for schedule and execute)

Note: you can skip cron_groups.xml step and define default group too as below

<group id="default">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.