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.
If there are some inter-dependency of module crons then that also can be accommodated in future work. Please ask if you need any further information.
Patch explanation
Patch simply renders a system_settting_form to user ( at admin/settings/cron-sched) to configure module specific cron run in multiple of system cron run ie. run module A's cron at each System cron run, run module B's cron at every fourth System cron run etc etc..
Selection of these option would-
* 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. This max number would be max limit of cron_freq_count. Counter will be reset to 1 when crosses max count.
Now whenever system cron runs drupal_cron_run() is invoked, it iterates the modules which has implemented cron hook. 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
| Comment | File | Size | Author |
|---|---|---|---|
| cron_patch.patch | 5.61 KB | nitinksingh |
Comments
Comment #1
seanburlington commentedHi,
this looks like something I would use :-)
But I'm on Drupal 5 ...
Changing the Version as this is a patch against drupal-6.2
Comment #2
stevenpatznew features go in the latest dev.
Comment #3
stevenpatzComment #4
nitinksingh commentedHi Spatz4000,
Could you please let me know where exactly more work is required in the patch?
Sorry for delayed response.
Comment #5
nitinksingh commentedComment #6
Anonymous (not verified) commentedThe last submitted patch failed testing.
Comment #7
Anonymous (not verified) commentedDuplicate of #154043: Cron should not remain monolithic (Implement a scheduling hook for cron)