runJobs should have a way to only run certain types of job
authorRiver Tarnell <river@users.mediawiki.org>
Fri, 11 May 2007 07:36:05 +0000 (07:36 +0000)
committerRiver Tarnell <river@users.mediawiki.org>
Fri, 11 May 2007 07:36:05 +0000 (07:36 +0000)
includes/JobQueue.php
maintenance/runJobs.php

index 3780e4f..1e96902 100644 (file)
@@ -38,6 +38,46 @@ abstract class Job {
         * static function queueLinksJobs( $titles ) {}
         */
 
+       /**
+        * Pop a job of a certain type.  This tries less hard than pop() to 
+        * actually find a job; it may be adversely affected by concurrent job 
+        * runners.
+        */
+       static function pop_type($type) {
+               wfProfilein( __METHOD__ );
+
+               $dbw = wfGetDB( DB_MASTER );
+
+
+               $row = $dbw->selectRow( 'job', '*', array( 'job_cmd' => $type ), __METHOD__,
+                               array( 'LIMIT' => 1 ));
+
+               if ($row === false) {
+                       wfProfileOut( __METHOD__ );
+                       return false;
+               }
+
+               /* Ensure we "own" this row */
+               $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ );
+               $affected = $dbw->affectedRows();
+
+               if ($affected == 0) {
+                       wfProfileOut( __METHOD__ );
+                       return false;
+               }
+
+               $namespace = $row->job_namespace;
+               $dbkey = $row->job_title;
+               $title = Title::makeTitleSafe( $namespace, $dbkey );
+               $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ), $row->job_id );
+
+               $dbw->delete( 'job', $job->insertFields(), __METHOD__ );
+               $dbw->immediateCommit();
+
+               wfProfileOut( __METHOD__ );
+               return $job;
+       }
+
        /**
         * Pop a job off the front of the queue
         * @static
index 91168e5..6e8e09f 100644 (file)
@@ -12,13 +12,28 @@ if ( isset( $options['maxjobs'] ) ) {
        $maxJobs = 10000;
 }
 
+$type = false;
+if ( isset( $options['type'] ) )
+       $type = $options['type'];
+
 $wgTitle = Title::newFromText( 'RunJobs.php' );
 
 $dbw = wfGetDB( DB_MASTER );
 $n = 0;
-while ( $dbw->selectField( 'job', 'count(*)', '', 'runJobs.php' ) ) {
+$conds = array();
+if ($type !== false)
+       $conds = array('job_cmd' => $type);
+
+while ( $dbw->selectField( 'job', 'count(*)', $conds, 'runJobs.php' ) ) {
        $offset=0;
-       while ( false != ($job = Job::pop($offset)) ) {
+       for (;;) {
+               $job = ($type == false) ?
+                               Job::pop($offset, $type)
+                               : Job::pop_type($type);
+
+               if ($job == false)
+                       break;
+
                wfWaitForSlaves( 5 );
                print $job->id . "  " . $job->toString() . "\n";
                $offset=$job->id;