Magento – Cron jobs stuck in running status

cronee-1.10email-reminders

Somehow our automated email reminder rules have stopped working meaning that our Abandoned cart emails have stopped sending. If I look in the cron_schedule table I see a few rows that have a status of running but they never seem to clear.

All in all I have 184 rows that are stuck in 'running' and the last one which seems to get generated when cron runs is in 'pending'.

schedule_id: 1679947
    job_code: send_notification
      status: running
    messages: NULL
  created_at: 2013-04-14 01:40:08
scheduled_at: 2013-04-14 01:45:00
 executed_at: 2013-04-14 01:50:10
 finished_at: 0000-00-00 00:00:00

schedule_id: 1845067
    job_code: send_notification
      status: pending
    messages: NULL
  created_at: 2013-07-22 15:45:04
scheduled_at: 2013-07-22 15:45:00
 executed_at: 0000-00-00 00:00:00
 finished_at: 0000-00-00 00:00:00

Can I just clear these jobs from cron schedule and if I do is that likely to make the email reminders start working again? What we don't want is for customers who had abandoned baskets to suddenly get a load of emails, we just want newly abandoned baskets to be notified.

Best Answer

Records in the cron_schedule table which are stuck in the running status like this are generally due to the PHP process encountering a fatal error. When a fatal error occurs, the job is halted, and Magento does not attempt to cleanup records left in the running status regardless of how long ago the execution was attempted.

In the example above, you are showing a record which has been hanging around for a few months. Those can be manually removed without causing any harm. A word of warning though… be careful not to remove running records which are for the current day (or previous day to be safe) as doing so will cause errors when the cron job is cleanup up after finishing the job.

If the same job is consistently failing and leaving these around, i.e. not going to a completed status very often, you'll want to dig into your PHP error logs and find out what the problem is. Considering you have over a hundred of these, I would take a look at your error logs to find the root cause. It may even be as simple as needing to increase the memory allocated to the PHP process running the cron, but could also be the result of a bug in the code which would need to be patched.

Related Topic