0

I Have created the custom cron in my custom module. 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 name="samplecron" instance="Learning\GreetingMessage\Cron\Run" method="execute">
<schedule>*/1 * * * *</schedule>
</job>
</group>
</config>

Then run.php

<?php
namespace Learning\GreetingMessage\Cron;
class Run
{
   protected $_logger;
   protected $_oredrcontroller;

   public function __construct(
       \Psr\Log\LoggerInterface $logger,
        \Learning\GreetingMessage\Controller\Index\Test $ordercontroller
   ) 
    {
     $this->_logger = $logger;
     $this->_oredrcontroller = $ordercontroller;
    }

   public function execute()
   {
       $this->_oredrcontroller->execute();
       $this->_logger->debug('Cron run successfully');
       return $this;
   }
}

I execute following commands in terminal

php bin/magento setup:upgrade
php bin/magento cache:flush
sudo chmod -R 777  .
php bin/magento cron:run

But my cron not working. In the function contorller \Learning\GreetingMessage\Controller\Index\Test execute . I wrote code to update values in my table. Nothing happens

  • Is the record falling in the cron_schedule table ? – Sourabh Kumar Sharma Nov 22 '18 at 9:41
  • @sourabh No i am not find any record with name "samplecron" in cron_schedule table – Sammu Sundar Nov 22 '18 at 9:43
  • Did you check your var/log folder and if there is any error ? – Sourabh Kumar Sharma Nov 22 '18 at 9:44
  • @sourabh In system.log i found "Cron Job samplecron is missed at 2018-11-22 08:08:00 [] []" – Sammu Sundar Nov 22 '18 at 9:46
0

Since your comment states that your error says that it is missing executing the cron I can suggest you the below step:

Go to Store -> Configuration -> Advanced -> System -> Cron (Scheduled Tasks) -> Cron configuration options for group: index you will get a setting called Missed if Not Run Within by default the value is 15 minutes, you can change it as per your requirement.

  • i am not able to find the menu configuration in system – Sammu Sundar Nov 22 '18 at 10:08
  • Edited the answer, you will find that option under store. – Sourabh Kumar Sharma Nov 22 '18 at 10:21
  • i did , still now i got main.INFO: Cron Job samplecron is missed at 2018-11-22 08:25:00 [] [] – Sammu Sundar Nov 22 '18 at 10:33

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.