4

I'm using Drupal 7, and set the cron job to run every hour.

However, when drupal cron runs, my CiviCrm schedule jobs does not run. These schedule jobs run only when I click the link "run all scheduled jobs manually".

Is there any way I can configure drupal cron job to run CiviCrm schedule jobs too?

Or I need to install any additional module, or configure setting so that the CiviCrm schedule jobs can run automatically?

2
  • Hi vences - there may be a better / direct way to PM you that I haven't discovered. Would be great if you could 'commit' to area51.stackexchange.com/proposals/77367/civicrm Nov 13, 2014 at 20:27
  • Yes and I had committed! :)
    – vences
    Nov 17, 2014 at 9:44

3 Answers 3

8

You should configure a separate cron entry for CiviCRM on your server. CiviCRM's Managing Scheduled Jobs is the reference documentation here.

Best practice is to run your CiviCRM cron separately.

  • Many CiviCRM tasks (eg delivering large email runs) are not suited to Drupal's typical cron schedule.
  • Running CiviCRM cron from Drupal means that an issue with another Drupal module timing out or causing cron to fail may prevent CiviCRM tasks running.
  • Likewise, running CiviCRM cron from within Drupal might prevent other Drupal cron tasks firing if CiviCRM cron timed out or failed.

While it may be possible to configure Drupal to run CiviCRM's cron (eg CiviCRM Cron or Elysia Cron modules), I wouldn't recommend that approach.

Things to check when debugging CiviCRM cron -

  • Are you calling cron from the same user account that your webserver runs as? CiviCRM cron tasks may write access to the templates_c/ directory and can fail if called as a user which can't write there.
  • Do the tasks execute when called from the CiviCRM Scheduled Tasks page? Visit civicrm/admin/job?reset=1 then click More > Execute Now
  • Is there output from the PHP command to execute CiviCRM cron? If so it may indicate errors. Use su to assume the user account your webserver runs as when doing this.

Since we use Drupal extensively with CiviCRM, we fire most site crons using

drush -u 1 @example.org civicrm-api job.execute auth=0 --out=json

where @example.org is a configured alias for the site in question.

We call CiviCRM cron frequently (max wait for a site is a few minutes) to reduce wait time and avoid queue buildups.

A cron entry for a site might look like this in /etc/cron.d/civicrm

[email protected]
*/7 * * * *    www-data    drush -u 1 @example.org civicrm-api job.execute auth=0 --out=json

... but you'll need to adjust this for your environment. You might want to call specific tasks frequently and others once a week; you definitely would need to check the user, Drush alias, and path to Drush shown above!

We also route our cron output to syslog for analysis, but that's well outside the scope of this. CiviCRM cron doesn't set the Drush output status (drush_log()'s $type parameter) as other Drush commands do.

1
  • NB. A colleague has pointed out the docs use auth=0 in the cron call also. AIUI this was required at some point in CiviCRM's past but is not any longer. But I've added it to the answer; as colleague points out, adding 6 chars is easier than digging through the codebase :) Input welcome here. Nov 13, 2014 at 23:10
3

The recommendation is to fire CiviCRM's cron for Scheduled Jobs directly from your server's cron job configuration:

Manual:

Scheduled jobs: These jobs must be triggered by a cron that runs regularly on your web hosting server.

Wiki:

Managing Scheduled Jobs: However, for most sites it is best to run the required jobs from the server command line, often as one or more automatically scheduled "cron" jobs.

There is a module out there, however, which aims to tie it into Drupal's cron: CiviCRM Cron. I haven't used it but it looks like what you are after, especially if you can't set the cron up on the server level.

Use Drupal's cron to call CiviCRM's cron. CiviCRM's cron can (and should) be called directly from the command line, but this is a simple way to define the user, pass, and sitekey used in the CiviCRM url and call CiviCRM's cron when it's not possible or convenient to configure CiviCRM's cron.

1

You might want to try the Elysia Cron module.

It will give you much more control over what cron jobs run and when. Its possible your cron job is timing out before it completes all of its jobs. You could use this module to configure your Civicrm cron job to run at a different time from other cron jobs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.