tags:

views:

45

answers:

3

I'm working on a wamp development environment and testing how long it takes to get the site indexed. I'm doing this by running cron manually.

The problem is that if there's 700 jobs in the job_queue, each run of cron does only some of them, so I need to run cron several times. How could I keep calling cron in a loop until there are no more jobs left in the job_queue?

Also, I'm open to any drush alternatives. I'm aware of drush cron, but this also does only some of the jobs each run, so needs to be run again manually.

+3  A: 
vlad b.
+2  A: 

How about something like this? I didn't test it as my drupal install doesn't have a 'job_queue' table, but you get the idea.

I also want to note that this is designed to be run from the CLI, not from the web.

#!/usr/bin/php
<?php

/* connect to the database */
$conn = mysql_connect('localhost', 'drupalusername', 'durpalpass');
if(!$conn) {
    die('Unable to connect to MySQL database. ' . mysql_error());
}

if(!mysql_select_db('drupaldb', $conn)) {
    die('Unable to select the database. ' . mysql_error());
}

$count = 1;

while($count > 0) {
    /* pull out our latest list of fields */
    $query =<<<EOD
    SELECT COUNT(*) as i FROM `job_queue`;
    EOD;

    $res = mysql_query($query);
    $row = mysql_fetch_assoc($res);

    $count = $row['i'];

    system('wget -O - -q -t 1 http://yourcron.php');
}

/* don't need it anymore */
mysql_close($conn);

?>
Nextraztus
Nextraztus
If you are going to write PHP code, you could write a PHP script to run through the cli and calling search_cron until there is no more node to index.
mongolito404
+5  A: 

If you want to run something all at once until it's done, cron is the wrong tool for the job; batch API is the tool for that. Unfortunately the search module is written to update only on cron, but there's not a lot of code in search_cron to copy into a batch function. So I'd suggest going the batch route rather wrapping some sort of pseudo-batch around cron, as your end goal doesn't seem to involve cron at all.

Scott Reynen