We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Cron job is one type of feature in magento 2. The cron job will create a command or a script that is appropriate with the task you want to do. Instead of manual working, the cronjob allows running automatically at time and we can perform some code based on cron job

    Module name : Magemonkeys_Magecron

    for we can create crontab.xml in moduleapp/code/Magemonkeys/Magecron/etc/crontab.xml

    <?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="MagemonkeysMagecronCronMycron" method="execute" name="magemonkeys_cron_mycron">
    			<schedule>* * * * *</schedule>
    		</job>
    	</group>
    </config>

    also here we have explain schedule start based an above code

    *   *  *  *  * command to be executed
    |  |  |  |  |
    |  |  |  |  +—– Day of week (0 – 7) (Sunday=0 or 7)
    |  |  |  +——- Month (1 – 12)
    |  |  +——— Day of month (1 – 31)
    |  +———– Hour (0 – 23)
    +————- Minute (0 – 59)

    and create Mycron.php file in module with relevant location app/code/Magemonkeys/Magecron/Cron/Mycron.php

    <?php
    namespace MagemonkeysMagecronCron;
    class Mycron
    {
        public function execute()
        {
    	$writer = new ZendLogWriterStream(BP . '/var/log/mycron.log');
    	$logger = new ZendLogLogger();
    	$logger->addWriter($writer);
    	$logger->info(__METHOD__);
    	return $this;
        }
    }

    after that cache flush and check

    If cron is not install in magento 2

    php bin/magento cron:install

    and then run cron

    php bin/magento cron:run

    Now you can check your cron schedule
    that’s it.

    field_5bfb909c5ccae

      Get a Free Quote