Better logging in runJobs.php. Committing for test on server.
[lhc/web/wiklou.git] / maintenance / runJobs.php
index d610b8c..e2a5895 100644 (file)
@@ -1,5 +1,11 @@
 <?php
 /**
+ * This script starts pending jobs.
+ *
+ * Usage:
+ *  --maxjobs <num> (default 10000)
+ *  --type <job_cmd>
+ *
  * @file
  * @ingroup Maintenance
  */
@@ -7,8 +13,6 @@
 $optionsWithArgs = array( 'maxjobs', 'type' );
 $wgUseNormalUser = true;
 require_once( 'commandLine.inc' );
-require_once( "$IP/includes/JobQueue.php" );
-require_once( "$IP/includes/FakeTitle.php" );
 
 if ( isset( $options['maxjobs'] ) ) {
        $maxJobs = $options['maxjobs'];
@@ -28,7 +32,7 @@ $conds = '';
 if ($type !== false)
        $conds = "job_cmd = " . $dbw->addQuotes($type);
 
-while ( $dbw->selectField( 'job', 'count(*)', $conds, 'runJobs.php' ) ) {
+while ( $dbw->selectField( 'job', 'job_id', $conds, 'runJobs.php' ) ) {
        $offset=0;
        for (;;) {
                $job = ($type == false) ?
@@ -39,10 +43,15 @@ while ( $dbw->selectField( 'job', 'count(*)', $conds, 'runJobs.php' ) ) {
                        break;
 
                wfWaitForSlaves( 5 );
-               print wfTimestamp( TS_DB ) . "  " . $job->id . "  " . $job->toString() . "\n";
+               $t = microtime( true );
                $offset=$job->id;
+               $status = $job->run();
+               $t = microtime( true ) - $t;
+               $timeMs = intval( $t * 1000 );
                if ( !$job->run() ) {
-                       print wfTimestamp( TS_DB ) . "  Error: {$job->error}\n";
+                       runJobsLog( $job->toString() . " t=$timeMs error={$job->error}" );
+               } else {
+                       runJobsLog( $job->toString() . " t=$timeMs good" );
                }
                if ( $maxJobs && ++$n > $maxJobs ) {
                        break 2;
@@ -50,3 +59,9 @@ while ( $dbw->selectField( 'job', 'count(*)', $conds, 'runJobs.php' ) ) {
        }
 }
 
+
+function runJobsLog( $msg ) {
+       print wfTimestamp( TS_DB ) . " $msg\n";
+       wfDebugLog( 'runJobs', $msg );
+}
+