| Project: | Drupal core |
| Version: | 7.x-dev |
| Component: | base system |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (duplicate) |
Issue Summary
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
| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| cron_patch.patch | 5.61 KB | Ignored: Check issue status. | None | None |
Comments
#1
I should have mentioned how it works. Here it goes..
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 satisfiedFinally it increases the cron_counter by 1 OR resets to 1 if it is crossing cron_max_count (LCM).
Nitin
#2
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
feature requests should start in 7.x now and then be backported.
#4
fyi, a more ambitious patch which has gone a bit stale: #87528: Multi-Threaded Cron Jobs
#5
Thanks!!
I'll look into that. :)
#6
Reroll patch against CVS/HEAD + coder style.
#7
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
#87528: Multi-Threaded Cron Jobs is a better approach.