Since Drupal 7 has now cron_key, we can't use wget method to call the cron.php without cron_key with the help of hosting_cron_use_backend variable.

I tried to fix this, so it will force backend method for any known D7 profile, even when hosting_cron_use_backend is set to false, by something like:

function hosting_cron_queue($count) {
  $sites = hosting_cron_get_sites($count);

  foreach ($sites as $site) {
    $site_name = hosting_context_name($site->nid);
    $profile = some_magic_fetch($site->profile);

    if (variable_get('hosting_cron_use_backend', TRUE) || preg_match("/(?:standard|minimal|testing|commerce|openpublic)/", $profile)) {
      provision_backend_invoke($site_name, "cron");
    }
    else {
      $cmd = sprintf("wget -O - -q %s  > /dev/null", escapeshellarg(_hosting_site_url($site) . '/cron.php'));
      drush_shell_exec($cmd);
    }

But don't know what to use in place of some_magic_fetch() :)

CommentFileSizeAuthor
#17 hostmaster_d7cron.patch13.98 KBacrollet
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

You can run wget cron on drupal7 if you know the magic key., i.e http://something.mig5.net/cron.php?cron_key=QCetwemZacZX4Ihg99CVt2352ans...

I wonder if we could be so clever as to detect drupal 7 in some way, and fetch that key from the variable table (does it get stored in there?) and therefore still support wget.

Might be crack-smokin' though ;) it could be quite a heavy bit of logic for something so small, and would involve bootstrapping the site in some way.

omega8cc’s picture

Or maybe we could store that cron_key in the drush alias for every D7 site? Then the only problem would be how to get it with some_magic_fetch(). Oh, context magic!

omega8cc’s picture

The reason why it could be useful is ability to speed up things on cron running via wget thanks to APC, which is not available (helpful) on php-cli.

omega8cc’s picture

The simple workaround is to enable Wget method for sites cron and then disable poormanscron module only for D5 and D6 platforms, so it will not cause possible issues. Aegir will silently fail to run cron for D7 platforms/sites, but D7 can still use its own built-in poormanscron, and benefit from APC like other platforms.

anarcat’s picture

Title: It is not possible to use wget method for d7 sites cron » wget cron method broken for d7 sites
Priority: Normal » Major

Bumping up priority. I agree this is a major annoyance - not sure how to get that key, is that a drupal token (http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_ge...)?

I would rather avoid poormanscron ...

Steven Jones’s picture

The cron key is a simple variable: http://drupalcode.org/project/drupal.git/blob/refs/heads/7.x:/cron.php

Can't we just store a random variable in the frontend/context, and push it into Drupal using our settings.php? That seems better than trying to pull it out of Drupal and get it back into our context or frontend?

Steven Jones’s picture

I'll probably take a look at this soonish anyway, unless someone objects or wants to do it?

Steven Jones’s picture

Status: Active » Needs review

I've had a quick go at this, in the dev-wget-d7-cron-1090678 branch, you'll need both hostmaster and provision branches for testing this.

Completely untested code, so it may not work at all, but I think the approach is correct. One small this is going to be that cloned sites are going to have the same cron key, but this would be the same as other Drupal sites if you 'cloned' them.

Steven Jones’s picture

So I've reviewed this, and actually made it work now, it still has the issue that cloned sites have the same key, but wget cron works with D7!

anarcat’s picture

Status: Needs review » Needs work

Instead of copying the key generation code from D7, isn't there a way the *backend* would generate the code and pass it back to the frontend?

This seems otherwise good and I would approve merging this in 2.x, if we resolve the above.

Steven Jones’s picture

Status: Needs work » Needs review

Right, I had a go at the 'alternative' of getting the cron_key from the backend and passing it to the frontend. Seems to work for me.

Possible refinement, I see that for clearing caches we use the magic Drush engines thing to clear caches in the same way, but I've coded my getting the cron key in a function with a conditional, is that okay?

Steven Jones’s picture

Additionally would you support getting this into the 1.x series too, currently drush based cron doesn't work very well for remote sites and wget doesn't work at all for D7...

anarcat’s picture

Yeah, I would support getting this in 1.x, after a short test life in 2.x. That said, again, I would prefer that the backend does this on the bootstrap, after the install/verify, than the frontend going around guessing.

Now of course if we port the frontend to d7... ;)

Steven Jones’s picture

Updated the branch to use a drush engine, tested and working, will merge in later if no one objects.

Steven Jones’s picture

Status: Needs review » Patch (to be ported)

So I've pushed into the the 7.x-2.x branch, and we can backport quite safely I think.

anarcat’s picture

if you have this working in 2.x and you tested it, feel free to merge back into 1.x.

acrollet’s picture

FileSize
13.98 KB

FWIW, I applied the attached patch from Steven Jones' branch against 6.x-1.1, and it Works For Me (tm). Thanks much!

Steven Jones’s picture

Status: Patch (to be ported) » Fixed

Merged into 6.x-1.x

Status: Fixed » Closed (fixed)

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

  • Commit 24fbfe3 on 7.x-2.x, dev-ssl-ip-allocation-refactor, dev-1205458-move_sites_out_of_platforms, 7.x-3.x, dev-588728-views-integration, dev-1403208-new_roles, dev-helmo-3.x by Steven Jones:
    Issue #1090678 by Steven Jones: Added wget cron method broken for d7...

  • Commit 24fbfe3 on 7.x-2.x, dev-ssl-ip-allocation-refactor, dev-1205458-move_sites_out_of_platforms, 7.x-3.x, dev-588728-views-integration, dev-1403208-new_roles, dev-helmo-3.x by Steven Jones:
    Issue #1090678 by Steven Jones: Added wget cron method broken for d7...