Create cron job in Magento

Create cronjob script in magento is very simple task, Which I have explain bellow with sample module called “CRM”.

First of all create a module. Now in module’s config.xml we will setup cron tab as bellow.

                <schedule><cron_expr>*/45 * * * *</cron_expr></schedule>

In above code,

<crm_customer_update> – is unique identifier, will be used as job_code in cron_schedule DB table

<schedule><cron_expr>* * * * *</cron_expr></schedule> – each asterisk stands for time period correspondingly: minutes, hours, days, months, years. If you leave it this way (* * * * *), cron job will be executed every minute. In our example, cron job will be run every 45 minutes <schedule><cron_expr>*/45 * * * *</cron_expr></schedule> or we can use alternative syntax to do that <schedule><cron_expr>0,15,30,45 * * * *</cron_expr></schedule>. If you want, for example, to run your job at 5 a.m., you need to do your cron expresion this way: <schedule><cron_expr>0 5 * * *</cron_expr></schedule>

Now the actual code for cron job will be unde,


class Mycode_Crm_Model_Customer extends Mage_Core_Model_Abstract
   public function sendUpdates() {
     //code here to be cron

2 thoughts on “Create cron job in Magento

  1. Pingback: Magento – Delete all cancelled magento orders | Tech Bandhu

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s