magento 2.3 cron job from custom module does not run automatically
-
20-03-2021 - |
문제
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?
올바른 솔루션이 없습니다
제휴하지 않습니다 magento.stackexchange