Question

I'm trying to disable a cron job that's scheduled in a Core file (for reasons), but I haven't been able to find any information about that on the manual or the Internet.

I found that the job I want to disable will leave under config > crontab> jobs > job_key config node, I was planning to overwrite the schedule > cron_expr within that node and set its value to null in my module.

Anyone with any experience in doing this? Any alternative solution?

Was it helpful?

Solution

I'm not sure if this is a recommended method or not, but it seems to work for me. You can create your own extension for the purpose of overriding cron and adjust the settings in the config.xml. To disable a core job, simply enter an empty cron_expr node.

For instance, We don't use the stock newsletter functionality in our store, so I wanted to disable the newsletter_send_all job. To do this I put the following in my config.xml:

<crontab>
    <jobs>
        <newsletter_send_all>
            <schedule><cron_expr></cron_expr></schedule>
        </newsletter_send_all>
    </jobs>
</crontab>

As I said, this seems to work well, but I'd welcome any feedback if someone thinks this is a bad idea for any reason.

OTHER TIPS

Cron jobs are scheduled through observers. The simplest way to disable one, is to rewrite the observer it is calling and reimplement the method to do nothing.

Future maintainers of your code will appreciate obvious naming and comments.

This has the additional advantage that you can implement your own toggle button in the backend. Your method will look something like this:

public function cronJobDoStuff($observer) {
    if( Mage::helper('my/module')->getEnableCronJobDoStuff() ) {
        return parent::cronJobDoStuff($observer);
    } else {
       return $this;
    }
}

You could probably replace the run > model node with your own method that does nothing:

<crontab>
    <jobs>
        <system_backup>
            <run>
                <model>my_module/observer::doNothing</model>
            </run>
        </system_backup>
    </jobs>
</crontab>

I recommend this module... Aoe/Scheduler We are using it and it is great for this kind of staff. Otherwise you have under System->Configuration->System->Cron (Scheduled Tasks) - all the times are in minutes->Disabled cron tasks... There you can provide crons that you want to disable.

I like the solution of @BrianVPS. Instead of leaving it empty, I propose to schedule it for "Feb 30", which will never occur.

<crontab>
    <jobs>
        <newsletter_send_all>
            <schedule>0 0 30 2 *</schedule>
        </newsletter_send_all>
    </jobs>
</crontab>

Haven't tested, but should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top