Create Magento cron programmatic task

I want to create a cron job task programmatically without using the config.xml file. Is it possible?

+3


source to share


2 answers


I don't see what the purpose of this is, and probably the best way to do it, but I think it should be done this way.

I've never had this case, but you can probably use the Mage_Cron_Model_Schedule class Mage::getModel('cron/schedule')

and set the data accordingly and then save. You need to define what the cron task is anyway in the config.xml for magento to be able to communicate.



It should populate the cron_schedule table so that it is checked for cron jobs.

+1


source


I found a solution at: http://www.ayasoftware.com/how-create-cron-jobs-dynamically-magento



$timecreated   = strftime("%Y-%m-%d %H:%M:%S",  mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")));
$timescheduled = strftime("%Y-%m-%d %H:%M:%S", mktime(date("H"), date("i")+ 5, date("s"), date("m"), date("d"), date("Y")));
$jobCode = 'job_id';

try {
    $schedule = Mage::getModel('cron/schedule');
     $schedule->setJobCode($jobCode)
        ->setCreatedAt($timecreated)
        ->setScheduledAt($timescheduled)
        ->setStatus(Mage_Cron_Model_Schedule::STATUS_PENDING)
        ->save();
   } catch (Exception $e) {
     throw new Exception(Mage::helper('cron')->__('Unable to save Cron expression'));
   }

      

+3


source







All Articles