2

I am writing custom cron to send a mail in every two minutes.I am also using it with AOE Scheduler extension.

Code:

/var/www/magento2/app/code/local/Produpdates/Notify/etc/config.xml

<?xml version="1.0"?>
    <config>
        <modules>
            <Produpdates_Notify>
                <version>1.0.0</version>
            </Produpdates_Notify>
        </modules>
        <global>
            <models>
                <notify>
                   <class>Produpdates_Notify_Model</class>
                </notify>
            </models>
            <events>
                <catalog_product_save_after>
                    <observers>
                        <notify>
                            <type>singleton</type>
                            <class>notify/observer</class>
                            <method>catalog_product_save_after</method>
                        </notify>
                    </observers>
                </catalog_product_save_after> 
             </events>  
        </global>  
       <crontab>
        <jobs>
            <send_newsletter_product_update>
                <schedule>
                    <cron_expr>*/2 * * * *</cron_expr>
                </schedule>
                <run>
                    <model>notify/observer::sendNewsletterProductUpdate</model>
                </run>
            </send_newsletter_product_update>
        </jobs>
    </crontab>       
</config>

/var/www/magento2/app/code/local/Produpdates/Notify/Model/Observer.php

<?php
include 'ctmail.php';

class Produpdates_Notify_Model_Observer
{
    public function catalog_product_save_after($observer)
    {
        $product = $observer->getProduct();    
    }

    public function sendNewsletterProductUpdate($schedule)
    {
        $html = 'Testing mail for CRON';
        $mail = Mage::getModel('core/email')
             ->setToName('Hiranya')
             ->setToEmail('test@example.com')
             ->setBody($html)
             ->setSubject('Sarees Images Collection')
             ->setFromEmail(Mage::getStoreConfig('trans_email/ident_general/email', $storeId))
             ->setFromName(Mage::app()->getStore()->getName())
             ->setType('html');
        try {
            $mail->send();
        } catch(Exception $error) {
            Mage::getSingleton('core/session')->addError($error->getMessage());
            return false;
        } 
    }
}

Problem: The scheduled cron is not working,only showing status as died

enter image description here

Browse other questions tagged or ask your own question.