Setup Cron In Local System.
1. Run the following command
crontab -e
2. Add the following command using terminal.
* * * * * /usr/bin/php /var/www/html/your_magento2_root_folder/bin/magento cron:run | grep -v "Run jobs by schedule" >> /var/www/html/your_magento2_root_folder/var/log/magento.cron.log * * * * * /usr/bin/php /var/www/html/your_magento2_root_folder/update/cron.php >> /var/www/html/your_magento2_root_folder/var/log/update.cron.log * * * * * /usr/bin/php /var/www/html/your_magento2_root_folder/bin/magento setup:cron:run >> /var/www/html/your_magento2_root_folder/var/log/setup.cron.log
Add Cron Jobs in Magento Custom Module.
1.Create 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="Namespace\Module\Cron\Taskname" method="execute" name="your_cron_job_title"> <schedule>*/5 * * * *</schedule> </job> </group> </config>
2.Create Taskname.php
File Path: File: app/code/Namespace/Module/Cron/Taskname.php
<?php namespace Namespace\Module\Cron; class Taskname { public function execute() { $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/cron.log'); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); $logger->info(__METHOD__); return $this; } }
0 Comments