To run a CiviCRM scheduled job using drupal cron we can follow the following steps:
 

  • Create a user in drupal having permission to run cron. This username and password is required to form the url to call the scheduled job.
     
  • In any custom module implement  ‘hook_cron’.
     
  • In the hook implementation, call the url for the scheduled job using curl.
     
  • The format of the url to run the scheduled job is as below:
    http://[SITEROOT]/sites/all/modules/civicrm/bin/cron.php?name=username&pass=password&key=site-key
     
  • This will run all scheduled jobs. To run a specific job we have to pass job=<api_action> and othere required parameters for that job.
    The value of <api_action> can be seen in the list of scheduled jobs in CiviCRM.

    The value of ‘site-key’ is in CIVICRM_SITE_KEY constant.
     
  • For example getting url to run the ‘Update Membership Statuses and Send Renewal Reminders’ job:

    global $base_url;
    $url=$base_url."/sites/all/modules/civicrm/bin/cron.php?job=process_membership&name=username&pass=password&key=".CIVICRM_SITE_KEY;

Add new comment