Surprisingly you might find the problem is actually down to a simple caching issue with a one line code fix. Magento caches it's cron schedule and reads this cached content on subsequent runs of cron rather than recreating the schedule each time to determine which jobs it should execute. The problem is sometimes jobs just don't get cached despite them being configured correctly so when the time comes for them to execute nothing actually happens.
It's worth noting that the cron schedule is cached even if all caching is disabled in admin, and the only way to clear the cached schedule through admin is to Flush Cache Storage under System->Cache Management. Unfortunately this doesn't then cause the jobs to be correctly cached the next time cron is run.
So the fix is to simply disable the caching of the cron schedule, and don't worry, benchmarks with caching disabled shows this to have no negative impact on site performance.
Copy:
app/code/core/Mage/Cron/Model/Observer.phpto:
app/code/local/Mage/Cron/Model/Observer.phpif it's not already there. Open the copied file and find the following line inside the generate() method:
Mage::app()->saveCache(time(), self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, array('crontab'), null);This is the line that initiates caching of the cron schedule, so just comment it out:
//Mage::app()->saveCache(time(), self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, array('crontab'), null);Save the changes and Flush Cache Storage to clear any currently cached cron jobs and your store should now always execute properly configured cron jobs.
Spent hours trying to work out why a new cron job was not showing up. The "Flush Cache Storage" button sorted it. Cheers :)
ReplyDeleteGreat, glad the above sorted out your cron problem.
DeleteYes I just noticed this when I finally decided to check it. I thought they were all running just fine. You have just given this solution to other problem. Thanks.
ReplyDeletewhere do you disable cron caching?
ReplyDeleteThis is just what I needed. My magento DB was becoming way too large and the cron wasn't emptying the log data. Thank you.
ReplyDeleteGreat, glad it helped you.
DeleteJust found this as i'm having problems with my product alerts not sending. I can't see which line needs taken out above, has it been removed?
ReplyDeleteCheers
The line to be commented still exists in the latest version of Magento CE (1.7.0.2 at the time of writing) and is still in the location as described above.
DeleteMy newsletter and Product Alert Emails are not working, this can fix the two?
ReplyDeleteBest Regards,
Marcelo
If the issues you are having are caused by cron jobs not running which should be, then it will probably fix the issue yes.
DeleteHi, in my magento store the path: "app/code/local/Mage/Cron/Model/" don't exist, I have to create?
DeletePS: I'm using magento v1.6.1.
Best Regards,
Marcelo
Hi Marcelo, yes create the path and copy the file over.
DeleteHi Hussey, the "Start Time" in "Product Alerts Run Settings" uses the server time?
DeleteMagento will schedule cron according to whatever timezone you have your install set to, this may not be the same as server time.
DeleteHi, unfortunately the tutorial don't worked for me, I made everything that is on the tutorial and put a product out of stock, after that I clicked in the link to receive stock alerts, I waited more then 24 hours to see if works, but I don't received any email about the product alerts, do you know what can be the problem?
DeleteHi Marcelo,
DeleteIt sounds like something else is stopping your cron jobs running correctly - this solution is proven to work when the caching of cron schedules is the problem.
I would be happy to look at your site and diagnose the issues you are having, if you would like me to then you can get in touch by following the link at the top to the Hussey Coding website and using the contact form there.
Hi, I tried to contact you using your contact form(Get in touch) but the submit button is not working.
DeleteHi Marcelo,
DeleteThe submit button will only become active when you have filled out each field correctly. Fields which are not correctly filled out are highlighted.
You are my here right now. Spend hours on figuring out why my custom cron job was not fired. It was cheduled, but never got to the succesfull state. Now it does. Thank you!
ReplyDeleteGlad it resolved your problem!
DeleteThanks for this. I spent two weekends trying to figure this one out. I thought only one item was not running properly... turns out there were a lot more. This should be a sticky one Magento's forums.
ReplyDelete