So, I have started an ambitous patch. For those who do not want to read the explination, and just gain knowledge by reading the patch:

This patch allows a user to run each modules cron job as it's own thread.

Right now, there is not a lot of information about cron runs other than "they run". I, as an admin, do lik elike this "black box" feature of something running every so often, but not telling me much about what it's doing, errors etc. What this patch does is allow a user to give drupal the command it uses to run cron.php, and it then fires of each modules cron hook in it's own thread. This has big benefits:

  1. Modules that my be "broken" do now interfear with other module runs
  2. Modules that take up a lot of time (e.g. search.module indexing a large site), will not "hog" all the run time. Each cron job has it's own "sandbox" to run in.
  3. Indivual tracking of modules
    1. This patch adds the ability to see the time that each module took to run.
    2. This reporting of each modules run can help a site admin better turn their site.

Note: This also has an option to "truncate" and keep only so many crons in history (simliar to watchdog

Note:It still allows for a "basic" cron.

I think this patch could lead to some interesting things, such as:

  • Setting individual time outs for each module
  • Capturing error messages during a cron run on a per module basis
  • Emailing an admin upon a "cron error" escalation, and information about which module it is.
  • Among other things.....

The basic program flow is as follows:
Cron Explincatoin

Here are some screen shots:

Cron Confiuration
Cron Configuration

Main Run Screen with 2 runs (1 basic, 1 advanced)
Cron Runs

Advanced Run

Thread Run

 

Basic RunBasic Run

Comments

Souvent22’s picture

Status: Active » Needs review

Up for review now.

boris mann’s picture

This is a very important patch....we need this to do more complicated and larger data sets.

moshe weitzman’s picture

Considering how ambitious the change is, I am surpirsed and pleased thhat the patch is not too large. Will review soon.

dries’s picture

This won't make it for 5.0 but might be useful for 6.0. My initial reaction is that we should avoid adding configuration settings. The UI needs some work too. That said, more advanced cron functionality is a useful feature.

coreb’s picture

Version: x.y.z » 6.x-dev

Moving out of the "x.y.z" queue to a real queue.

An important patch like this needs to be in the right place.

coreb’s picture

Status: Needs review » Patch (to be ported)

By the time someone gets to this, it will need to be ported.

RobRoy’s picture

Status: Patch (to be ported) » Needs review

The "to be ported" state is for patches that have been contributed to HEAD and need to be backported to 4.7 or 4.6 for example. So this still needs review before that would happen.

@coreb - Not sure if there's any other issues that were incorrectly marked "to be ported". Let me know if you find any and have questions on the correct status. Thanks!

m3avrck’s picture

Subscribing...

FiReaNGeL’s picture

Subscribing... and at the same time, could we implement some sort of cron ordering? Let's say I want to make sure that aggregator cron (or some other module) runs before one of my custom module (I don't think it's possible right now).

forngren’s picture

Subscribing and adding to my 6.x todo-list.

moshe weitzman’s picture

HEAD is again open. lets get this one in front of the committers.

chx’s picture

Status: Needs review » Needs work

I advise using proc_open not popen.

killes@www.drop.org’s picture

The patch is somewhat dangerous, cron_run_command should be a bit sanitized and even then, I am not sure I like it.

Souvent22’s picture

Yes. Agreed about the dangerousness of the current patch. I have cleaned it up a lot. I shall try and post the updated patch this week.

Souvent22’s picture

StatusFileSize
new19.62 KB

This is just a "re-sync" patch to get back in line with 5.1. It has been tested though and works.

The way I currently tested it is I have a few custom modules for clients paired with large datasets that have very long run-times.
Another easier way to test this is to modify existing cron runs. E.g.:

Try putting a sleep(15); line in the watchdog cron function, and run your cron manually. You will see that the page returns saying cron run-secucessful. If you go over to admin/logs/cron and select the newest cron run, you'll see that watchdog will wtill still be running and the amount of time it has been running.

The basics are there, just needs some heavy tweaking, cleaning and polishing.

Souvent22’s picture

Killes,

I'm trying to come up with a scenario where the cron_run_command could be compromised as a "primary" opening. Meaning, if someone gains access to your MySQL database, and changes the variable in the database...there are larger security issues at hand.
However, my current scenario that I can think of is someone gains a drupal installations administrator's username/password, and changes the executable to "rm -r " or something malicious like that.

However, if you're running an important drupal site a secure sever, then Drupal (PHP) should not be running as a privileged user anyways.

Thoughts?

Souvent22’s picture

I'll update this module if/after SQL Server goes into head, thus I don't have to keep 2-3 sets of db creation patches up to date after each head change. blah. :)

m3avrck’s picture

Reroll?

owen barton’s picture

Subscribing

wim leers’s picture

Version: 6.x-dev » 7.x-dev

Subscribing.

liquidcms’s picture

subscribing

boris mann’s picture

Maybe work on this for HEAD and backport. It's needed.

moshe weitzman’s picture

Anyone up for reviving this. HEAD is open and accepting patches :)

lilou’s picture

StatusFileSize
new47.92 KB
new22.84 KB

Mark #246380: Module wise cron scheduling interface. as duplicated.

Update patch #15 for D7, but fail on install :

Notice: Undefined index: rid in drupal_cron_run() (line 2800 of includes\common.inc).
kehan’s picture

subscribing

Antinoo’s picture

subscribing

frankcarey’s picture

bump

lilou’s picture

Issue tags: +cron

Add tag.

Souvent22’s picture

Ok. I have a need and some time :). I'm going to start to port this to a contrib-module instead of a patch against core.
After it gets vetted there, we can look at perhaps bringing into core.
I'll update as time permits. I'm going to work against D6 for the first implementation.

owen barton’s picture

@Souvent22 - did you see http://drupal.org/project/cron_mt? It uses pcntl for managing threads, and it looks like the basic framework is there, and a lot of the issues solved (or at least identified). It would be great to work on that module (and perhaps see if a pclose(popen()) type approach is indeed sufficient) rather than duplicating work here.

cpliakas’s picture

I would be very willing to work with, or at least have a discussion with, anyone who wants to add support for non-unix-like systems to Cron MT. Right now it is a fairly simple solution that works very well on Linux, which is the platform on which I exclusively develop. To goal of the module it to be as light weight and transparent to the end user as possible, and unfortunately I have not been able to come up with a similar solution on Windows probably because of my lack of low-level knowledge of the OS.

alex_b’s picture

Does #578676: Use queue for cron render this patch obsolete?

chx’s picture

Status: Needs work » Closed (duplicate)

It does.

barbank’s picture

Why not port over the SuperCron module by 63reasons?