5

I have a little problem (which should be easy to solve), with a custom module I try to execute through crontab. For now, the only thing it is supposed to do is to print a log entry in dev.log file. Unfortunately, it doesn't, that's why I look for some help.

Below is how I've created my module.

app/etc/modules/Mycompany_Cronmodule.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_Cronmodule>
            <active>true</active>
            <codePool>local</codePool>
        </Mycompany_Cronmodule>
    </modules>
</config>

app/code/local/Mycompany/Cronmodule/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_Cronmodule>
            <version>1.0</version>
        </Mycompany_Cronmodule>
    </modules>

    <global>
        <models>
            <cronmodule>
                <class>Mycompany_Cronmodule_Model</class>
            </cronmodule>                         
        </models>
    </global>

    <crontab>
        <jobs>
            <mycompany_cronmodule>
                <schedule><cron_expr>* * * * *</cron_expr></schedule>
                <run><model>cronmodule/observer::test</model></run>
            </mycompany_cronmodule>
        </jobs>
    </crontab>
</config>

app/code/local/Mycompany/Cronmodule/Model/Observer.php

class Mycompany_Cronmodule_Model_Observer {

    public function test(){
        Mage::log("TEST success", null, "dev.log");
    }
}

I have configured my windows task manager to execute cron.php every 5 minutes which works perfectly to send Magento emails (I run a local instance on a local windows with wamp).

Do you have any hints ?

1
  • Is it needed to do crontab -e and enter the cron job in this or no? I am trying to copy your solution but still no success. Dec 5, 2016 at 14:47

2 Answers 2

2

It seems, that I have nothing wrong in my code, after cleaning the cache, I can see in the table magentocron_schedule a lot of Cronmodule tasks pending (and some executed). I also have my output in my log file which is perfect.

Thanks to this post to give me the hint to clean the cache: Can't get cron job to work

0

For run the cron job,you need to add time interval properly

<schedule><cron_expr>* * * * *</cron_expr></schedule>

to

<schedule><cron_expr>*/5 * * * *</cron_expr></schedule>
2
  • 1
    As for me <cron_expr>* * * * *</cron_expr> also workable
    – zhartaunik
    Apr 13, 2015 at 10:20
  • 1
    <schedule><cron_expr>* * * * *</cron_expr></schedule> is a valid interval. It means execute the task every minutes.
    – chris
    Apr 13, 2015 at 10:23

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.