When we run cron.php of magento then some jobs created in cron_schedule table of magento ? Can anyone let me know how magento execute these jobs exactly ? I mean how job status is changed from pending to success. Cron.php only insert jobs in the table not execute jobs
1 Answers
You'd want to read through the following article available directly from the MagentoCommerce website which covers all that you need to know about cron functionality & Magento:
Magento - Wiki - How to Set Up a Cron Job
To highlight: Inner workings
Magento crontab mechanism is triggered periodically using system cron job. The call is initiated in cron.php file:
<?php
// 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 taskjob_code- job identifier from configurationstatus- can be one ofpending, running, success, missed, errormessages- custom text reported by method that was executed by the jobcreated_at- date/time when the task was created atscheduled_at- date/time when the task is planned to be executedexecuted_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,
statusis set topending,created_attonow()andscheduled_atto 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.
-
Hurry for the documentation which Magento preserved... – janw Jan 05 '16 at 15:01
-
@janw pardon me? – Moose Jan 07 '16 at 08:11
-
1The link above is broken (general redirect). I hate how Magento broke all those links. – janw Jan 07 '16 at 08:12
-
1Yeah, it is upsetting, the same with their forum information too. Anyway, I did copy most of the article into my answer so it's still relatively complete :) – Moose Jan 07 '16 at 08:14