1

Magento 2 custom corn is not working in my custom module.

app/code/Namespace/ModuleName/etc/crontab.xml

<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="review_reminder_cronjob" instance="Namespace\Modulename\Cron\ReminderEmail" method="execute">
        <schedule>* * * * *</schedule>
    </job>
</group>
</config>

app/code/Namespace/Modulename/Cron/ReminderEmail.php

<?php
namespace Namespace\Modulename\Cron;

use Psr\Log\LoggerInterface;

class ReminderEmail
{
    /**
    * Write to system.log
    *
    * @return void
    */

    public function execute()
    {        
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info('Test cron worked successfully');
    }
}

Run below command :

php bin/magento cron:run

Something is missing or wrong in the code above. can anyone help me to solve out this?

I have already tried below way.

Edit : In my database cron status is Missed or Error

enter image description here

Any help would be appreciated!

  • please specify "not working" – Philipp Sander Apr 9 at 6:57
  • </config> is missing in the XML. therefor it's not valid – Philipp Sander Apr 9 at 6:58
  • is the module enabled? did you run setup:upgrade and clear the caches? – Philipp Sander Apr 9 at 6:59
  • which OS you are using? – Avesh Naik Apr 9 at 7:00
  • 1
    Your job name is test_reminder_cronjob but as per as ,your screenshot your job name is different – Amit Bera Apr 9 at 9:20
3

Setting cron job in Linux server using below command.

1) Check cron are set or not using below command.

crontab -l

2) Going to magento root Set cron job using below command.

php bin/magento cron:install -f
  • @ChiragPatel is this help for setup cronjob? – Kamlesh Solanki Apr 9 at 7:15

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.