4

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?

5

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.

| improve this answer | |
1

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;
    }
}
| improve this answer | |
  • posted that your solution made sense before but, while implementing it, I realized that I would like to avoid that task being scheduled at all; i.e. calling a doNothing method is fine, but why should we call it in the first place? I'll keep investigating. Thanks! – manei_cc Mar 27 '15 at 10:46
  • Preventing the task being scheduled, means you need to modify the code of the extension / core, if it doesn't provide a means to disable it. All code in the core, provides a way to disable a job via the backend as far as I know (maybe not the Email sending in 1.9.1), but not all extensions do this. You have to weigh "fully optimized" versus "maintainability" and this is something only you can answer. – Melvyn Mar 27 '15 at 15:07
1

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>
| improve this answer | |
  • This worked for me EE 1.14.1.0 cheers, just make sure the module configuration you put them in depends on the module you are disabling. – jzahedieh Jun 10 '15 at 12:30
1

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.

| improve this answer | |

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.