1

I created a custom cron job in my custom module. But, when I check the cron schedule, it's all in pending and don't work at all like in the picture below. Does that mean there's error on my cron job?

Cron Job schedule : cron

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="custom_crongroup">
        <job name="custom_cronjob" instance="Test\Show\Cron\Test" method="execute">
            <schedule>* * * * *</schedule>
        </job>
    </group>
</config>

Cron/Test.php :

<?php
namespace Test\Show\Cron;
use \Psr\Log\LoggerInterface;

class Test {
    protected $logger;

    public function __construct(LoggerInterface $logger) {
        $this->logger = $logger;
    }

/**
   * Write to system.log
   *
   * @return void
   */

    public function execute() {
        $this->logger->info('Cron Works');
    }

}
1

Check the cron log for any errors. Make sure var/log folder have 777 permissions. If you still didn't find any solution, paste your crontab.xml file and the file your running.

  • 777 permission does not work, please check my crontab and cron file in my question. – Edwin Widhiyanto Dec 7 '17 at 6:06
  • have you created custom cron group named custom_crongroup ? . If you not created the group then create custom cron group or else change the group name to index/default. Already tutorials are available for creating cron groups devdocs.magento.com/guides/v2.0/config-guide/cron/… – Venugopal Chikkegowda Dec 8 '17 at 5:29
  • yes i created it already, and i follow that link too anyway. – Edwin Widhiyanto Dec 8 '17 at 9:05
  • Any errors in cron log ? – Venugopal Chikkegowda Dec 11 '17 at 5:29
  • There's no error on cron log, nothing showed but it's all always pending – Edwin Widhiyanto Dec 12 '17 at 10:33
1

Please Try : Write in crontab.xml = group id="default"

To test : php bin/magento cron:run --group="default"

It will work for me

  • I have set index and run command but its not working for me – Sarvesh Tiwari Jul 14 '18 at 9:53
1

You must run cron twice: the first time to discover tasks to run and the second time — to run the tasks themselves. The second cron run must occur on or after the scheduled_at time for every task

Refer the office doc

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.