One way you could do this, as @ user3438533 mentioned, is to schedule work when your observer fires, which can be done later by cron. This is safe because jobs scheduled in the future with pending status in cron_schedule will not be cleared.
Since you purchased the purchase, let's use it as an example. You will need to create a simple extension to put this into effect. The general event used to complete things after placing an order is sales_order_place_after , so we will use it to run a future cron custom job.
etc. /config.xml
Step 1 Configure the event observer in config/frontend/events :
<sales_order_place_after> <observers> <scheduleExampleJob> <class>My_Example_Model_Observer</class> <method>scheduleExampleJob</method> </scheduleExampleJob> </observers> </sales_order_place_after>
Step 2 Set up a cron job handler that will listen to the new custom job created in the observer in config/crontab/jobs :
<my_example_job> <run><model>My_Example_Model_Observer::runExampleJob</model></run> </my_example_job>
Model /Observer.php
class My_Example_Model_Observer { /** * Triggers my_example_job to get scheduled when it gets fired. * @param Varien_Event_Observer $observer * @return $this */ public function scheduleExampleJob(Varien_Event_Observer $observer) { // Calculate your needed datestamp to schedule the future job. $scheduleAt = Mage::getModel('core/date')->timestamp('Ymd H:i:s', strtotime('30 minutes from now')); Mage::getModel('cron/schedule') ->setJobCode('my_example_job') // Needs to match config/crontab/jobs node ->setStatus(Mage_Cron_Model_Schedule::STATUS_PENDING) ->setScheduledAt($scheduleAt) ->save(); } /** * Handler for my_example_job, executed from crontab. * @param $schedule * @return $this */ public function runExampleJob($schedule) { // Do your asynchronous work! return $this; } }
source share