In the Magento 2 CLI, the command to run cron jobs is cron:run --group="[cron group]"

However, I was not able to find how this translates into actual PHP code, i.e. where cron:run is mapped to.

Is it possible to execute cron:run programmatically from within my module? Something like:

function run() {
  • Can you explain a bit more on why you would need to do that? Thanks Commented Jul 10, 2019 at 14:55
  • Actually it's for testing purposes--I have a module that executes a number of behaviors in the main Magento 2 module and provides a REST interface to control this. I could imagine some other use cases though, i.e. if someone wanted to run all crons at a certain frequency regardless of the actual frequency defined by the module developer, etc.
    – Ynhockey
    Commented Jul 10, 2019 at 14:59
  • what have you tried to achieve this? Commented Jul 10, 2019 at 15:00
  • I tried checking what Magento itself run on cron:run, but beyond that I really don't have any direction.
    – Ynhockey
    Commented Jul 10, 2019 at 15:06

1 Answer 1


Inside here


$params[self::INPUT_KEY_GROUP] = $input->getOption(self::INPUT_KEY_GROUP);

$cronObserver = $objectManager->create(\Magento\Framework\App\Cron::class, ['parameters' => $params]);

So basically you are passing $params['group'] = whatever

And then


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.