4

I am trying to customize Ebizmart Mailchimp extension. This extension has few batch processing which are run by Cron job. My Server is in Ubuntu VM and my IDE is netbean run on Windows. Debugging elsewhere is fine.

By customizing Ebizmart Mailchimp extension, I’ll collect specific subscribers and send them to mailchimp account. If I could trace its underlying php files which are run by cron job, I could easily modify its model.

Thanks.

1
  • For things like this I generally isolate functionality and trigger via my own console commands. Debug in console script. Once confirmed working as expected or whatever then i work back into a cron process. Context in console and cron are the same. Commented Jun 26, 2019 at 23:09

3 Answers 3

4

You could use Magerun. Magerun contains a command through which you can manually trigger a cronjob.

use the following command and then select a number for the specific job:

Magento 1

n98-magerun.phar sys:cron:run

https://github.com/netz98/n98-magerun#run-cronjob

Magento 2

n98-magerun2.phar sys:cron:run

https://github.com/netz98/n98-magerun2

2
  • 1
    Yes, I can run specific Cron Job in this way. That was not my issue. When I run that Cron Job, I want to run debugger and debug that method as well. How is it possible?
    – Wasim
    Commented Aug 27, 2018 at 7:01
  • @Wasim if you're using xdebug you can prefix this command with 'XDEBUG_CONFIG=idekey=PHPSTORM' or whatever, or whatever the key may be in your case. Commented May 10, 2022 at 14:50
4

Create a new file, for example, test.php and put it in your magento2 pub directory with the following code:

<?php
require __DIR__ . '/../app/bootstrap.php';

class TestMyClass
    extends \Magento\Framework\App\Http
    implements \Magento\Framework\AppInterface
{
    public function launch()
    {
        $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
        $myClass = $this->_objectManager->create('NameSpace\YourClassName');
        $myClass->execute(); // In cron jobs we usually use the execute() method as the entry point
        return $this->_response;
    }
}

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('TestMyClass');
$bootstrap->run($app);

And then run yourdomain.local/test.php

2

Here is what I am using:

list cron jobs-> magerun sys:cron:list

run specific cron job -> sys:cron:run [cron_job_name]

I would like to know more about tools to help debugging.

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.