3

I have a Drupal 6 site and I have a custom module that performs some maintenance operations on certain nodes when cron is run.

My code is very simply:

function mymodule_cron() {
  // get all the nodes that need maintenance
  $result = db_query("SELECT * FROM {mymodule_nodes}");

  while ($row = db_fetch_object($result)) {
    // load the node
    $node = node_load($row->nid); // Causes Drush Error

    // Perform Maintenance Tasks
  }
}

The trouble is, when I run cron using drush core-cron, it fails and says: "drush command terminated abnormally due to an unrecoverable error"

Using some basic debugging skills, I traced the problem to the node_load call. Is there a reason why calling node_load in cron in this way causes drush core-cron to fail?

-sh-4.1$ drush status
 Drupal version         :  6.17
 Database               :  Connected
 Drupal bootstrap       :  Successful
 Drush version          :  4.5
 Drush configuration    :
 Drush alias files      :
-sh-4.1$ php -v
PHP 5.3.6 (cli) (built: Mar 17 2011 20:56:13)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
-sh-4.1$ httpd -v
Server version: Apache/2.2.17 (Unix)
Server built:   Oct 27 2010 10:04:21

Running the Cron Job from the web interface works fine without error. The problem seems to be drush related.

I checked watchdog and whenever I try to run this from drush, Watchdog shows a new message under the cron Type saying "Cron run exceeded the time limit ans was aborted". Strange thing is, I get the error almost immediately after hitting enter from the CLI and in my current implementation, I'm simply trying to debug the node_load so I've got my maintenance tasks commented out. I'm just trying to dump the node title of the first one in the list to the screen and then returning true, so it should only be looping once.

The reason why this is such a problem is because the only way we've been able to get cron to run from crond is by using drush. But if drush can't execute this command, then I'm at an impasse.

Even using Drush 5 doesn't resolve the problem.

apaderno
  • 28,547
  • 16
  • 75
  • 90
seismicmike
  • 103
  • 1
  • 9
  • Does `drush -v core-cron` give you any more information that might be helpful? – nmc Apr 04 '12 at 18:44
  • nmc, Thanks for the suggestion. drush -v core-cron just tells me "WD cron: Cron run exceeded the time limit and was aborted. [warning]" – seismicmike Apr 05 '12 at 14:15
  • Is `$row->nid` null? See http://drupal.org/node/123269#comment-629789 – nmc Apr 05 '12 at 14:37
  • Good question, I just wrapped an if (!is_null($row->nid)) {} around the node_load call and it still failed. – seismicmike Apr 05 '12 at 15:55
  • Run drush --debug core-cron and look at the timings. You should not try to process _all_ nodes. This could hit the [fixed time limit for cron runs in Drupal (http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_cron_run/6). Better do it like node_update_index() - process a small number of nodes every cron run. – rik Apr 14 '12 at 05:32
  • Re: small number of nodes at a time, Drush 5 has queue integration. – Grayside Apr 18 '12 at 06:54
  • rik, I ran it with --debug and it fails [0.43 sec, 36.44 MB]. I'm not sure if that tells you anything. Essentially, what I'm doing here is tracking a list of nodes in a separate table that I need to do maintenance on later and I'm running through this list of nodes, so I'm not sure how using indexing will change anything. – seismicmike Apr 25 '12 at 17:46

1 Answers1

0

Do you have the PHP filter module enabled? I bet someone put some bad code in one of your nodes. This is one of the many reasons that php module should never be used....

matt2000
  • 1,064
  • 11
  • 17