
How To Setup A Cron Job In Magento – Magento Cron Tutorial

A CRON is a daemon which keeps running and gets activated at a said interval (time period). Cron helps store owners to setup up and schedule commands which will run periodically at set time and date. Various Magento services such as “Sending Newsletter “, Cleanup with logs, Cleanup cache, Customer notification etc. requires a mechanism where store owners can setup and schedule commands to run periodically.
Most of the web hosts have their own set of task scheduler; you can ask and verify the task scheduler from your webhost. While setting a cron-job make sure that minimum time duration is set to run every 15 minutes (not less than this) as Magento spends around 1 minute to index 1000 products and sets the status to “Success” from “Pending”.
Now to setup Crontab in Magento go to Admin => system => configuration => system => ‘Cron (Scheduled Tasks)’ tab.
You will notice that all times are in minutes.
Magento Cron Best Practices
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
run the cron every 15 minutes for better results and that will not overlap with other Cron services.
What goes in the background
When you set the Cron this will happen
1 2 3 4 5 6 7 8 | // initialize configuration and load event observers only from /crontab/ section Mage::getConfig()->init()->loadEventObservers('crontab'); // initialize crontab event area Mage::app()->addEventArea('crontab'); // dispatch 'default' event for observers specified in crontab configuration Mage::dispatchEvent('default'); |
This sequence will invoke Mage_Cron_Model_Observer→dispatch(), which in turn will:
-
execute scheduled tasks
-
generate future scheduled tasks if needed
-
clean up history of scheduled tasks
Tasks are scheduled for each time the job needs to be run based on
-
<schedule><cron_expr>0 1 * * *</cron_expr></schedule>
expression and stored in cron_schedule table.
Each record consists of the following fields:
-
schedule_id– unique identifier for scheduled task -
job_code– job identifier from configuration -
status– can be one ofpending, running, success, missed, error -
messages– custom text reported by method that was executed by the job -
created_at– date/time when the task was created at -
scheduled_at– date/time when the task is planned to be executed -
executed_at– date/time when the task was actually executed (null prior to execution) -
finished_at– date/time when the task finished execution (null prior to execution)
When schedules are generated, status is set to pending, created_at to now() and scheduled_at to target date/time.
When pending schedules are executed, status is set to running and executed_at to now().
When scheduled task is finished successfully, status is set to success and finished_at to now().
When scheduled task has thrown an exception, status is set to error and finished_at to now().
If task status is pending and scheduled_at is older than “Missed if not run within” configured value, status is set to missed.
Please leave me a comment and let me know if you have any problems setting up cron in Magento. Subscribe our RSS to receive latest updates.
-
http://rainytech.co.cc/operating-systems/how-to-set-up-windows-7-xp-mode/ How To: Set-Up Windows 7 XP Mode | Rainy Technology
-
Dawa
-
http://www.magentomagik.com/ MagentoMagik
-
Avinash
-
Anonymous
-
dawa
-
http://www.magentomagik.com/ Ashish @Magento Themes
-
http://www.3.com Kristan Lerper
-
http://maque.org.ua/wordpress/?p=10432 Що таке Cron і навіщо він потрібен | maque.org.ua
-
Emilshamloo
-
Vishal Porwal
-
Swapna Silu
- How To Setup & Manage Multiple Stores In Magento Commerce
- How To Install Magento Extensions - Magento Extension Installation Guide
- Extra Fee Magento Extension - Addtional Charges Extension
- Magik Slider Extension - Magento Community Extension
- How To Install A Magento Theme - Ultimate Magento Theme Tutorial
- Adding New Shipping Module In Magento
- How To Add Lightbox To Magento Theme
- Free Magento Theme - ElectroMagik
- How To Display Best Selling Products On Magento Store Home Page
- MagentoMagik Autocomplete Search Extension - Magento Extension
Magento Development
Magento Extensions
Magento Hosting
Magento How To
Magento Installation
Magento News
Magento Product Import
Magento Themes


