diff -urp ./includes/common.inc ../drupal-6.2/includes/common.inc --- ./includes/common.inc 2008-04-10 02:41:44.000000000 +0530 +++ ../drupal-6.2/includes/common.inc 2008-04-14 13:11:15.000000000 +0530 @@ -2525,7 +2525,25 @@ function drupal_cron_run() { variable_set('cron_semaphore', 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', time()); diff -urp ./modules/system/system.admin.inc ../drupal-6.2/modules/system/system.admin.inc --- ./modules/system/system.admin.inc 2008-03-25 17:28:16.000000000 +0530 +++ ../drupal-6.2/modules/system/system.admin.inc 2008-04-14 13:23:44.000000000 +0530 @@ -1425,6 +1425,62 @@ 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("1" => "each", "2" => "alternate","3" => "every third","4" => "every fourth","5" => "every fifth","0" => "Never",); + 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 diff -urp ./modules/system/system.module ../drupal-6.2/modules/system/system.module --- ./modules/system/system.module 2008-04-10 02:41:49.000000000 +0530 +++ ../drupal-6.2/modules/system/system.module 2008-04-14 13:14:54.000000000 +0530 @@ -101,6 +101,9 @@ function system_help($path, $arg) { return t('An advanced action offers additional configuration options which may be filled out below. Changing the Description field is recommended, in order to better identify the precise action taking place. This description will be displayed in modules such as the trigger module when assigning actions to system events, so it is best if it is as descriptive as possible (for example, "Send e-mail to Moderation Team" rather than simply "Send e-mail").'); 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.') .'
'; + } } @@ -422,6 +425,14 @@ function system_menu() { 'access arguments' => array('administer site configuration'), 'file' => 'system.admin.inc', ); + $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.',