Module wise cron scheduling interface.

nitinksingh - April 14, 2008 - 09:13
Project:Drupal
Version:7.x-dev
Component:base system
Category:feature request
Priority:normal
Assigned:Unassigned
Status:duplicate
Description

Hello,

I am developing a module which requires frequent cron runs than other modules. In other words, I must be able to configure module wise cron run frequency. For example: What if search indexing cron has to run everyday but update checking cron only once in a week?

AFAIK drupal invokes all cron hooks whenever cron.php is run. Clearly there is a need to provide module wise cron scheduling customization interface to users.

To provide above feature I have created a simple patch (attached). It would be great if someone can review the code and comment on its usability.

Patch simply gives an interface to user ( at admin/settings/cron-sched) to configure module specific crons in multiple of system cron run ie. run this at each cron run, run that at every fourth cron etc. If there are some inter-dependency of crons then that also can be accommodated. Please ask if you need any further information.

Nitin

AttachmentSizeStatusTest resultOperations
cron_patch.patch5.61 KBIgnoredNoneNone

#1

nitinksingh - April 14, 2008 - 09:48

I should have mentioned how it works. Here it goes..

  • This will set cron_freq_module param to user selected frequency ie. 1 for running at each run(default), 2 for running on alternate cron run, 0 for never etc etc...
  • Initialize cron_counter to 1.
  • Set cron_max_count to LCM (Least common multiple) of available options

Now whenever system cron runs ie. drupal_cron_run() is invoked it builds list of modules which has implemented cron hook instead of invoking module_invoke_all('cron'). While iterating the list it fetches cron_freq_module param and checks whether this cron_hook has to be invoked or not. It invokes the hook, if condition is satisfied

Finally it increases the cron_counter by 1 OR resets to 1 if it is crossing cron_max_count (LCM).

Nitin

#2

mattconnolly - June 20, 2008 - 07:26

I wouldn't bother with the maximum count (LCM) since the modulus operator % will keep every task running at each Nth execution.

Alternatively, you could keep a list of each frequency value, and if they all % to 0 the reset the counter to 0.

Let us know how the module is coming along. :)

#3

Susurrus - June 20, 2008 - 16:08
Version:6.2» 7.x-dev

feature requests should start in 7.x now and then be backported.

#4

moshe weitzman - June 22, 2008 - 12:36

fyi, a more ambitious patch which has gone a bit stale: #87528: Multi-Threaded Cron Jobs

#5

nitinksingh - June 26, 2008 - 14:56

Thanks!!
I'll look into that. :)

#6

lilou - October 26, 2008 - 14:26

Reroll patch against CVS/HEAD + coder style.

AttachmentSizeStatusTest resultOperations
issue-246380-6.patch5.83 KBIgnoredNoneNone

#7

keith.smith - October 26, 2008 - 14:37
Status:needs review» needs work

I didn't apply this patch, or test it in situ, but with a read-through, it needs a good bit of work, both on substance and coding style.

+      return '<p>'. 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 <b>every third</b> for Module ALFA then module ALFA\'s cron will run on every third run of system cron. In order to schedule <a href="http://drupal.org/cron"> System Cron</a> please make a crontab entry in your *nix machine or add a Task in your Task Scheduler on windows machine.') .'</p>';

There are a lot of issues in the one string I've pasted above, for instance.

#8

lilou - November 8, 2008 - 20:49
Status:needs work» duplicate

#87528: Multi-Threaded Cron Jobs is a better approach.

 
 

Drupal is a registered trademark of Dries Buytaert.