3

I'm working on a custom module to export any new orders periodically throughout the day. I've read through countless descriptions of how to set up cron with for a custom module and it seems like I'm doing everything right, but yet it doesn't seem to be doing anything. The module is showing as enabled in admin and the default cron jobs are running. I'm using a custom name for my module's cron group, but that group does not show up when I attempt to configure it under Stores > Configuration > Advanced > System and my job never shows up on the cron_schedule table.

Here is my vendor/module/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="custom_group">
        <job name="custom_name" instance="<vendor>\<module>\Cron\Test" method="execute">
            <schedule>*/5 * * * *</schedule>
        </job>
    </group>
</config>

and my vendor/module/Cron/Test.php

<?php
namespace spinst\OrderExport\Cron;
use \Psr\Log\LoggerInterface;

class Test {
    protected $logger;

    public function __construct(LoggerInterface $logger) {
        $this->logger = $logger;
    }

    public function execute() {
        $this->logger->info('Cron Works');
    }

}

Does anyone have any tips as to what I could be doing wrong?

1 Answer 1

9

You need to do one of the following options:

1) Use <group id="default"> in vendor/module/etc/crontab.xml

or

2) Create your own vendor/module/etc/cron_groups.xml with the following:

<?xml version="1.0"?>
<!--
/**
 * path:
 * magento_home/app/code/vendor/module/etc/cron_groups.xml
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/cron_groups.xsd">
    <group id="custom_group">
        <schedule_generate_every>1</schedule_generate_every>
        <schedule_ahead_for>4</schedule_ahead_for>
        <schedule_lifetime>2</schedule_lifetime>
        <history_cleanup_every>10</history_cleanup_every>
        <history_success_lifetime>60</history_success_lifetime>
        <history_failure_lifetime>600</history_failure_lifetime>
        <use_separate_process>1</use_separate_process>
    </group>
</config>

This will then show up in your backend Stores->Configuration->Advanced->System under Cron.

To test : php bin/magento cron:run --group="custom_group"

3
  • Hi Hsmith92 and Joseph G-H. I'd like to use this as a tutorial on Magento devdocs. I can mention each of you as contributors to the topic and link to your web site if you have one. All I need are your first and last names and the link. Thanks! Commented Nov 1, 2016 at 22:12
  • No problem go ahead and use it! Glad it helps! Henry smith (dont worry about a link)
    – Hsmith92
    Commented Nov 16, 2016 at 14:30
  • 1
    Adobe doc is misleading. It says "You may declare a new group and specify its configuration options in cron_groups.xml" but it sould be "You MUST declare..."
    – baoutch
    Commented Mar 31, 2023 at 20:15

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.