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
1 2 3 4 5 6 7 8 |
<?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="Magemonkeys\Magecron\Cron\Mycron" 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
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php namespace Magemonkeys\Magecron\Cron; class Mycron { public function execute() { $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/mycron.log'); $logger = new \Zend\Log\Logger(); $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.
[crayon-63e09b5cbcde4005472889/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.