PoormansCron: The Next Generation

Dave Reid - September 27, 2009 - 19:23
Project:Poormanscron
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Dave Reid
Status:closed
Description

Revised the entire module to be a simple backport of the current D7-style poormanscron (#331611: Add a poormanscron-like feature to core). It runs using an AJAX request instead of in hook_exit(). And it includes the issue to solve creating two separate Drupal requests on every page load by just using JavaScript to run the poormanscron request (#566494: Cron image does a full bootstrap on every page request (including cached ones)).

This version is completely D7-compatible so when the user upgrades to Drupal 7 the automatica cron setting should already be set up and ready to go.

AttachmentSize
poormanscron-TNG-D6.patch10.7 KB

#1

Dave Reid - September 27, 2009 - 19:23
Status:active» needs review

#2

Dave Reid - September 27, 2009 - 20:07

Including tests!

AttachmentSize
poormanscron-TNG-D6.patch 13.37 KB

#3

Rob Loach - September 27, 2009 - 20:25
Status:needs review» reviewed & tested by the community

Including tests?! Damn skippy! Think we should wait for #566494: Cron image does a full bootstrap on every page request (including cached ones) to go through? Still not entirely sure what solution will end up going through. Either way, this is still good for an initial testing DRUPAL-6--2!

#4

Dave Reid - September 27, 2009 - 20:29

Seems like #566494: Cron image does a full bootstrap on every page request (including cached ones) is going to have a lot of objectors, but I really really like that approach. Plus, I don't think we can do the <noscript> solution since we don't have a hook_page_alter() in D6. Revised patch that passes all tests and tested locally.

AttachmentSize
poormanscron-TNG-D6.patch 13.36 KB

#5

sun - September 27, 2009 - 21:30
Status:reviewed & tested by the community» needs work

+++ poormanscron.js 27 Sep 2009 20:27:54 -0000
@@ -0,0 +1,16 @@
+        alert('Running cron!');

hm?

+++ poormanscron.module 27 Sep 2009 20:27:54 -0000
@@ -7,88 +7,108 @@
+if (!defined('DRUPAL_CRON_DEFAULT_THRESHOLD')) {
+  define('DRUPAL_CRON_DEFAULT_THRESHOLD', 10800);
+}

Constants have to be in the namespace of the defining module. It doesn't matter whether this is a backport.

+++ poormanscron.module 27 Sep 2009 20:27:54 -0000
@@ -7,88 +7,108 @@
+if (!defined('REQUEST_TIME')) {
+  define('REQUEST_TIME', time());
}

Please don't. Defined constants are irreversible, and modules are loaded sequentially. Use time() instead.

I'm on crack. Are you, too?

#6

Dave Reid - September 27, 2009 - 21:37
Status:needs work» needs review

Oh, yeah, I should take out the alert. But at least I can see it's working. :) Removed the DRUPAL_CRON_DEFAULT_THRESHOLD constant. Begrudgenly removing REQUEST_TIME because the performance implications of calling time() multiple times. I just reworked poormanscron_run_cron_check() to call time() once and re-use the result.

AttachmentSize
589438-poormanscron-TNG-D6.patch 12.98 KB

#7

sun - September 27, 2009 - 21:43

+++ poormanscron.module 27 Sep 2009 21:37:06 -0000
@@ -6,89 +6,103 @@
+if (!defined('REQUEST_TIME')) {
+  define('REQUEST_TIME', time());
+}
...
+function poormanscron_run_cron_check() {
...
+  $time = time();

Great - though you missed to remove the constant.

btw, time() can be called thousands of times before it starts to have any measurable performance impact.

The reason for introducing REQUEST_TIME was a different one.

This review is powered by Dreditor.

#8

Dave Reid - September 27, 2009 - 21:49

Hah, thanks. :) Really appreciate the reviews.

AttachmentSize
589438-poormanscron-TNG-D6.patch 12.83 KB

#9

sun - September 27, 2009 - 22:39
Status:needs review» reviewed & tested by the community

#10

Dave Reid - September 29, 2009 - 22:37
Status:reviewed & tested by the community» fixed

6.x-2.0 branch created and now using this code. Thanks everyone!

#11

mikeytown2 - September 30, 2009 - 01:12

Quick question, does this embed the cron ajax/image callback for every page? or does it only inject it when cron is needed. Thinking about page caching and how this would effect it. I would prefer it was embedded in every page; maybe make it an option for people wanting it either way.

#12

Dave Reid - September 30, 2009 - 01:17

The way it works is it injects a JavaScript variable timestamp for when the next cron run should happen, along with poormanscron.js which tests if the current time is greater than the 'target' timestamp, then it creates the ajax request to run cron.

#13

mikeytown2 - September 30, 2009 - 01:24

Cool, thanks for the info. Works how I hopped it would!

#14

TheRec - September 30, 2009 - 21:33

Subscribing... (no I won't complain about <noscript>, don't worry :P ... I know it is fixed, just archiving)

#15

System Message - October 14, 2009 - 21:40
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.