1

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?

2
  • I'm having the same issue and I will look into this in the upcoming days. – Philipp Sander Nov 19 '19 at 9:08
  • Sorry for not replying sooner. I finally discovered that was a weird customization server side that was causing the issue, so it's not magento related. In my case, I was able to discover the issue by looking at all the logs file created by magento: they kept telling that they couldn't find classes and stuff. That was because somebody had changed the position of the php ini file so when I ran the cron manually everything worked but the crontab couldn't find it. – Lounik Dec 13 '19 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.