1

I have created a new module with my crontab.xml :

<config>
    <group id="default">
        <job name="order_read" instance="Cincuenta\CronOrders\Model\Orders" method="readOrders">
            <schedule>*/5 * * * *</schedule>
        </job>
    </group>
</config>

Also i got a CronOrders/Model/Orders.php with the function :

public function readOrders(){


        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/loggy.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info('LOG1');
...

I had try to run by command with

php bin/magento cron:run

and

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

But the log is not been created. I also tested my log code and it runs in others functions well.

Any error with the crons in Magento 2 or I'm missing something?

2
  • Do you try run cron:run two times?
    – KAndy
    Commented May 4, 2016 at 15:29
  • I had already runned cron:run like 100 times trying to get the error.
    – ntzz
    Commented May 4, 2016 at 15:34

2 Answers 2

4

You can use magerun for testing out your cron code.

Just download it to the root folder of your project and then run

php n98-magerun2.phar sys:cron:list to get a list of all registered crons

php n98-magerun2.phar sys:cron:run [cron code] to run a specific cron job

It has all sort of magento2 utility commands as well, just run

php n98-magerun2.phar to get a list of all available commands

Hope this helps !!

2
  • super buddy. it is very very useful !!!! :-) Commented Sep 3, 2016 at 11:15
  • 1
    Working Sir Ji. Commented Aug 16, 2017 at 14:41
0

Okay i missed some code on 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="order_read" instance="Cincuenta\CronOrders\Model\Orders" method="readOrders">
            <schedule>*/5 * * * *</schedule>
        </job>
    </group>
</config>

I added in <config> this line:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.