Posted on

On working from Pukekohe

One of the perks of working from Pukekohe a couple of times a week is it has a rural vibe, reminiscent of Palmerston North where I grew up. Paddock Bashing a car is somewhat a rite of passage in rural NZ though a BMW 735 is significantly more luxurious than the 1981 Mazda 323 I raced in my youth. I’ll let the pictures tell the story…

PS: I’ll write an actual Magento related blog post soon too, it looks like a month since I last wrote anything, but I dropped an article on Magebase earlier this month about Magento Session storage, have you read it?

IMG_0083
Continue reading On working from Pukekohe

Posted on

Cloud Backup Case study: Detecting if Magento cron is running in your extensions

We released the latest version of our Magento Cloud Backup extension, for sending a full site and database backup offsite to Amazon’s cloud storage service S3. You can read about the latest release over on the World Wide Access site. In this post I wanted to quickly cover the method I used for detecting if cron is running on a Magento store. This was one of the new features added to help new users identify possible problems.

I think it’s important for many extensions that rely on cron to check if it is running, because otherwise it’s possible for users to have a false sense of security (particularly around automated backups). This technique I mentioned briefly back in October at the Magento Developers Paradise. This more fully worked example will hopefully be useful to others.

The logic is this: If we have no pending jobs, or no successful jobs in the Magento cron table, then cron is probably not running (either it never has, or only has once).

$schedules_pending = Mage::getModel('cron/schedule')->getCollection()
        ->addFieldToFilter('status', Mage_Cron_Model_Schedule::STATUS_PENDING)
        ->load();
$schedules_complete = Mage::getModel('cron/schedule')->getCollection()
        ->addFieldToFilter('status', Mage_Cron_Model_Schedule::STATUS_SUCCESS)
        ->load();
 
 if (sizeof($schedules_pending) == 0 || 
        sizeof($schedules_complete) == 0) {
                // cron probbaly isn't running
}

With this code run from within a frontend model, or a controller, you can effectively inform your users that cron is probably not running. It would be quite a nice service actually that just automatically calls cron for Magento stores via the web.

It would also be possible to look at when the last successful job completed, if it was days ago then it may also be a clue that cron has been running, but has since stopped. If anyone has an alternative approach, please let me know I’d like to hear it.