Magento Cron System is used to run tasks on recurring basis as with any cron based system. “cron.php” located in magento base folder is the main entry for magento cron system.Magento cron you need to put “http://yourdomainname.com/cron.php” in your web server cron job
There are various default cron job setup already in magento, so its recommend that you setup cron in magento. The default cron jobs in magento are related to log cleaning, newsletter, product stock notifications, currency updates.
Add cron to your module
Add following xml to your custom module’s config.xml
default> <crontab> <jobs> <job_unique_name> <schedule> <cron_expr>0 2 * * *</cron_expr> </schedule> <run> <model>test/observer::cronMethod</model> </run> </job_unique_name> </jobs> </crontab> </default>
These settings are given below :
- Generate Schedules Every: After how many minutes should we generate a new cron entry in database
- Schedule Ahead for: How many minutes ahead should the cron entry be done in database.
- Missed if Not Run Within: Mark status as missed if cron has not run with these many minutes
- History Cleanup Every: Delete cron entry after how many minutes
- Success History Lifetime: After how many minutes to delete a cron entry with status success
- Failure History Lifetime: After how many minutes to delete a cron entry with status failure
Cron job details in Magento
To implement cron in magento, follwing files refers,
Mage::getConfig()->init()->loadEventObservers('crontab'); Mage::app()->addEventArea('crontab'); Mage::dispatchEvent('always'); Mage::dispatchEvent('default');
<crontab> <events> <default> <observers> <cron_observer> <class>cron/observer</class> <method>dispatch</method> </cron_observer> </observers> </default> <always> <observers> <cron_observer> <class>cron/observer</class> <method>dispatchAlways</method> </cron_observer> </observers> </always> </events> </crontab>