2

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?

4

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"

  • 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! – Steve Johnson Nov 1 '16 at 22:12
  • No problem go ahead and use it! Glad it helps! Henry smith (dont worry about a link) – Hsmith92 Nov 16 '16 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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