Question

I've created a custom module with a cron task. If I call the cron from cli with

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

I can see my custom cron in the cron_schedule table and it gets excecuted successfully.

But if I don't run the cron manually, no task is added to the table. Default magento cron are running, so the cron itself is working (installed by magento command cron:install).

What I did:

  • I created the 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 name="custom_name" instance="<vendor>\<module>\Cron\Test" method="execute">
            <schedule>* * * * *</schedule>
        </job>
    </group>
</config>
  • I've created the Cron/Test.php cron file:
<?php
namespace Vendor\Module\Cron;
use \Psr\Log\LoggerInterface;

class Test {
    protected $logger;

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

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

}
  • I've upgraded and cleaned cache from cli:
$ php bin/magento setup:upgrade
$ php bin/magento cache:flush
  • I've tested the cron by calling it manually:
$ php bin/magento cron:run 

At this point, everything is working: after calling the cron:run a couple of times, I can see my custom cron in the cron table and its status is "success".

  • So I leave it there for a while, then go and check the table again. I expect to see my custom cron added to the table and run every minute. What I see instead is no further cron job is added.

What's wrong? How can I solve this?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top