Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Schedule cronjob for module
 
michielh
Jr. Member
 
Total Posts:  22
Joined:  2011-03-04
 

Hi guys,

I’ve just started programming my own magento module. The module itself works; I’ve tested it out using the ‘catalog_product_save_after’ hook, and all the neccessary fields are visible in the backend.

The problem arises when I try to hook my plugin to crontab. The first time I added the crontab XML-code and reinstalled plugin (by clearing cache + deleting module table + deleting core_resource table entry), a cronjob entry was added in the cron_schedule table. This cronjob was executed and “success"-ed after execution ( I received an email). However, the cronjob wasn’t re-scheduled and reinstalling didn’t work. I tried everything, but without success. My settings are as follows:

/app/code/local/Mysite/Awesomeplugin/etc/config.xml:
    <
crontab>
        <
jobs>
            <
mysite_awesomeplugin_tester>
                <
schedule><cron_expr>0,30 * * * *</cron_expr></schedule>
                <
run><model>awesomeplugin/observer::tester</model></run>
            </
mysite_awesomeplugin_tester>
        </
jobs>
    </
crontab>

/app/code/local/Mysite/Awesomeplugin/Model/Observer.php:
class 
Mysite_Awesomeplugin_Model_Observer
{
public function tester() {  
mail
'info@mysite.com','test','test');
return 
$this;
}
}

cronjob settings
cpanel:
*/15 * * * * /usr/local/bin/php /home/myaccount/domains/mysite.com/public_html/cron.php >/dev/null 2>&1;

Magento
Generate Schedules Every 60
Schedule Ahead for 1
Missed if Not Run Within 60
History Cleanup Every 120
Success History Lifetime 120
Failure History Lifetime 120

While checking cron_schedule, all the other modules are added/refreshed except mine. Has anyone got a lead in what direction to search for regarding this matter?

Thanks in advance!

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagikMahesh
Member
 
Total Posts:  36
Joined:  2012-04-10
 

Initially I had the same problem with cron,

<crontab>
        <
jobs>
            <
company_module
                
<schedule>
                    <
cron_expr>10 16 * * *</cron_expr><!-- daily at 16 hours 10 mins -->
                </
schedule>
                <
run>
                    <
model>moduleobserver::cronJobMethod</model>
                </
run>
            </
company_module>
        </
jobs>
    </
crontab>
i use this code for my cron job.
When i run cron.php exact at 16:00 then it creates entry in schedule but not run at 16:10
then i rerun cron.php after 16:10 them it runs my cron job.
Here is a point that your cron.php should run cron on befor 5-10 min and after 5-10 min cron schedule .
First you change the cron expression to
<cron_expr>* * * * *</cron_expr><!-- runs at every minute -->
this will run your cron schedule every minute, and also run the cron.php twice to see whether it add entry in scheduler or not.
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top