1

I have followed the tutorial on Magento dev docs to create a custom crontab. Checking the cron_schedule table and various logs, I can see that cron is successfully running M2 jobs (e.g. indexer, mailers), but not the custom crontab. There is no mention of it at all - no errors in the Magento or server logs; no entry in cron_schedule.

I have manually run cron serveral times, seeing the message "Ran jobs by schedule" each time. I have set cron to log to var/log/magento.cron.log, and there I see only the same "Ran jobs by schedule" message - no other output from the other M2 cron jobs which I know are running (because they show status "success" in cron_schedule).

The custom module crontab (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="cronjob_default" instance="Vex\SportIntBase\import\StoredProcCronDefault" method="execute">
            <schedule>* * * * *</schedule>
        </job>
    </group>
</config>

The class:

namespace Vex\SportIntBase\import;
use \Psr\Log\LoggerInterface;

class StoredProcCronDefault
{
    protected $_logger;
    private $_fetchers;

    const PATH = __DIR__ . 'vendor/vex/module-sport-int-base/import';

    public function __construct(LoggerInterface $logger) {
        $this->_logger = $logger;
        $this->_fetchers = array(
            'price_fetch.php',
            'products_fetch.php',
            'stock_fetch.php'
        );
    }

    public function execute() {
        $this->_logger->info('Beginning VexSport Stored Procedure Run (default)');
        foreach($this->_fetchers as $runSP) {
            include(SELF::$PATH) . $runSP;
        }
    }
}

Version info: M2 2.1.2, PHP 7.0.13, Debian 8.6.

Thanks for any ideas or suggestions. I'm stumped.

2 Answers 2

2

I think this is Usefull for you,

You need to use n98-magerun2 this will show all the error in cron jobs,

Download and Install Phar File

<m2-dir>$ wget https://files.magerun.net/n98-magerun2.phar

After seen in have n98-magerun2.phar file. with in m2-directory

next you need to list all the cron jobs, follow this command:

<m2 -dir> $ ./n98-magerun2.phar sys:cron:list

then, run cron job:

<m2- dir> $ ./n98-magerun2.phar sys:cron:run [cron jobname]

This will show you where error occur in your code.

follow this link

2
  • n98-magerun.phar is just for M1, while the author is asking for M2 solution
    – PY Yick
    Jun 30, 2017 at 5:25
  • @PYYick i updated my answer, check it n98-magerun2.phar is there in magento 2 Jun 30, 2017 at 5:31
0

I think you should check the log on the folder: /project/var/log

Anyway, you can test with a script for logs: For Magento <= 2.4.2

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/logfile.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Simple Text Log'); // Simple Text Log
$logger->info('Array Log'.print_r($myArrayVar, true)); // Array Log

For Magento >= 2.4.2

$writer = new \Laminas\Log\Writer\Stream(BP . '/var/log/test.log');
$logger = new \Laminas\Log\Logger();
$logger->addWriter($writer);
$logger->info('Your text message');
$data = ["test" => "testing"];
$logger->debug(var_export($data, true));

So run cronjob by hand:

php bin/magento cron:run

Your Answer

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

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