Featured post

Magento® 2.x How to create basic frontend module

How to create basic frontend module in Magneto 2 ?? Step 1. Decide a name space(Extendtree) & module name(Helloworld). Ex. Extendtre...

Saturday, 3 September 2016

Magento 1.x ® Cron Job- How to create basic cron module.

How to use Magneto crons??

  • Step 1. Create global configuration File
  • Step 2. Create module configuration file
  • Step 3. Create module model observer

Step 1. Each Module should have one Namespace & Module name. Name space could be some company name etc. & module name should be something that represents module functionality. So let suppose Namespace is ExtendTree and Module name is SimpleCrons. Now Create Global Configuration File inside root directory /app/etc/modules as name "ExtendTree_SimpleCrons.xml"

<!--xml version="1.0" encoding="UTF-8"?--> <config> <modules> <ExtendTree_SimpleCrons> <active>true</active> <codePool>local</codePool> </ExtendTree_SimpleCrons> </modules> </config>

Step 2. Now Create Module Configuration File inside the directory /app/code/local/ExtendTree/SimpleCrons/etc as name "config.xml"

<!--xml version="1.0"?--> <config> <modules> <ExtendTree_SimpleCrons> <version>0.0.1</version> </ExtendTree_SimpleCrons> </modules> <global> <models> <simplecrons> <class>ExtendTree_SimpleCrons_Model</class> </simplecrons> </models> </global> <crontab> <jobs> <first_cron_setup_in_one_minute> <schedule> <cron_expr>* * * * *</cron_expr> </schedule> <run> <model>simplecrons/cron::doThisInMinute</model> </run> </first_cron_setup_in_one_minute> </jobs> <jobs> <second_cron_setup_in_two_minute> <schedule> <cron_expr>*/2 * * * *</cron_expr> </schedule> <run> <model>simplecrons/cron::doThisInTwoMinute</model> </run> </second_cron_setup_in_two_minute> </jobs> </crontab> </config>

Step 3. Now next thing is to create model cron inside the directory /app/code/local/ExtendTree/SimpleCrons/Model/ as name "Cron.php"

class ExtendTree_SimpleCrons_Model_Cron { /* * This cron will run in one minute. */ public function doThisInMinute() { /** * Write your custom code here */ Mage::log('One minute completed', null, 'FirstCron.log'); } /* * This cron will run in two minutea. */ public function doThisInTwoMinute() { /** * Write your custom code here. */ Mage::log('Two minute completed', null, 'SecondCron.log'); } }

That's it..!! Now as per your server cron setup. It should create a log file in one and two minute interval inside the directory /var/log

Thank you..!!

"The easy way for everything."

No comments :

Post a Comment