? sites/default/files ? sites/default/settings.php Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.810 diff -u -p -r1.810 common.inc --- includes/common.inc 22 Oct 2008 19:39:36 -0000 1.810 +++ includes/common.inc 26 Oct 2008 14:13:20 -0000 @@ -2716,7 +2716,25 @@ function drupal_cron_run() { variable_set('cron_semaphore', REQUEST_TIME); // Iterate through the modules calling their cron handlers (if any): - module_invoke_all('cron'); + $count = variable_get("cron_counter", 1); + $max = variable_get("cron_max_count", 1); + // List of modules implemented cron hook. + $cron_mods = module_implements("cron"); + + foreach($cron_mods as $key => $mod){ + $freq = variable_get("cron_freq_$mod", 1); + // Never run case. + if($freq == 0) { + continue; + } + // Invoke module specific cron hook at user defined frequency. + if(!($count % $freq)){ + module_invoke($mod, "cron"); + } + } + // Increase the counter. + $count = ($count + 1) > $max ? 1 : $count + 1 ; + variable_set("cron_counter", $count); // Record cron time variable_set('cron_last', REQUEST_TIME); Index: modules/system/system.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v retrieving revision 1.102 diff -u -p -r1.102 system.admin.inc --- modules/system/system.admin.inc 16 Oct 2008 20:23:08 -0000 1.102 +++ modules/system/system.admin.inc 26 Oct 2008 14:24:27 -0000 @@ -1495,6 +1495,77 @@ function system_image_toolkit_settings() } /** + * Form builder; Configure System cron settings. Sets module specific cron + * running frequencies. + * + * @ingroup forms + * @see system_settings_form() + */ +function system_cron_sched_settings(){ + $cron_mods = module_implements('cron'); + $options = array( + '0' => 'Never', + '1' => 'each', + '2' => 'alternate', + '3' => 'every third', + '4' => 'every fourth', + '5' => 'every fifth', + ); + foreach($cron_mods as $key => $mod){ + $form["cron_freq_$mod"] = array( + '#type' => 'select', + '#title' => ucfirst($mod).' Module', + '#weight' => -1, + '#default_value' => variable_get("cron_freq_$mod", 'each'), + '#options' => $options, + '#description' => t('Cron will run as per above selection.'), + ); + } + //Filter never option. + $options = array_diff_key($options, array('0' => 'dummy')); + $form['cron_max_count'] = array( + '#type' => 'hidden', + '#value' => _cron_lcm_array(array_keys($options)), + ); + $form['cron_counter'] = array( + '#type' => 'hidden', + '#value' => 1, + ); + + return system_settings_form($form); +} + +/** + * Math helper function to calculate LCM (Least common multiple) of an array. + */ +function _cron_lcm_array($items){ + while(2 <= count($items)){ + array_push($items, _cron_lcm(array_shift($items), array_shift($items))); + } + return reset($items); +} + +/** + * Math helper function to calculate LCM (Least common multiple) of two numbers. + */ +function _cron_lcm($n, $m) { + return $m * ($n/_cron_gcd($n, $m)); +} + +/** + * Math helper function to calculate HCD (Highest Commo divisor). + */ +function _cron_gcd($n, $m) { + $n = abs($n); + $m = abs($m); + if ($n == 0 and $m == 0) + return 1; + if ($n == $m and $n >= 1) + return $n; + return ($m < $n) ? _cron_gcd($n-$m, $n) : _cron_gcd($n, $m-$n); +} + +/** * Form builder; Configure how the site handles RSS feeds. * * @ingroup forms Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.632 diff -u -p -r1.632 system.module --- modules/system/system.module 14 Oct 2008 20:44:57 -0000 1.632 +++ modules/system/system.module 26 Oct 2008 14:17:29 -0000 @@ -99,6 +99,8 @@ function system_help($path, $arg) { return '

' . t('IP addresses listed here are blocked from your site before any modules are loaded. You may add IP addresses to the list, or delete existing entries.') . '

'; case 'admin/reports/status': return '

' . t("Here you can find a short overview of your site's parameters as well as any problems detected with your installation. It may be useful to copy and paste this information into support requests filed on drupal.org's support forums and project issue queues.") . '

'; + case 'admin/settings/cron-sched': + return '

'. t('Cron scheduling gives you option to configure module wise cron run frequency. You can set whether some module\'s cron should run on every system cron run or it should run periodically after a fix number of system cron. For example, if you are selecting every third for Module ALFA then module ALFA\'s cron will run on every third run of system cron. In order to schedule System Cron please make a crontab entry in your *nix machine or add a Task in your Task Scheduler on windows machine.') .'

'; } } @@ -583,6 +585,14 @@ function system_menu() { 'page arguments' => array('system_image_toolkit_settings'), 'access arguments' => array('administer site configuration'), ); + $items['admin/settings/cron-sched'] = array( + 'title' => 'Cron Scheduling', + 'description' => 'Choose cron frequency for modules.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('system_cron_sched_settings'), + 'access arguments' => array('administer site configuration'), + 'file' => 'system.admin.inc', + ); $items['admin/content/rss-publishing'] = array( 'title' => 'RSS publishing', 'description' => 'Configure the number of items per feed and whether feeds should be titles/teasers/full-text.',