Revert r81542 for now, too lazy to fix this properly
[lhc/web/wiklou.git] / maintenance / runJobs.php
index a100034..0edf7ac 100644 (file)
@@ -2,6 +2,10 @@
 /**
  * This script starts pending jobs.
  *
+ * Usage:
+ *  --maxjobs <num> (default 10000)
+ *  --type <job_cmd>
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -27,9 +31,9 @@ class RunJobs extends Maintenance {
                parent::__construct();
                $this->mDescription = "Run pending jobs";
                $this->addOption( 'maxjobs', 'Maximum number of jobs to run', false, true );
+               $this->addOption( 'maxtime', 'Maximum amount of wall-clock time', false, true );
                $this->addOption( 'type', 'Type of job to run', false, true );
                $this->addOption( 'procs', 'Number of processes to use', false, true );
-               $this->addOption( 'exclusive', 'Run only one exclusive runJobs script at a time. Timeout is 1800 seconds. Useful for cron scripts.', false );
        }
 
        public function memoryLimit() {
@@ -38,10 +42,6 @@ class RunJobs extends Maintenance {
        }
 
        public function execute() {
-               if ( $this->lock() === false ) {
-                       exit( 0 );
-               }
-
                global $wgTitle;
                if ( $this->hasOption( 'procs' ) ) {
                        $procs = intval( $this->getOption( 'procs' ) );
@@ -50,11 +50,12 @@ class RunJobs extends Maintenance {
                        }
                        $fc = new ForkController( $procs );
                        if ( $fc->start() != 'child' ) {
-                               $this->unlock();
                                exit( 0 );
                        }
                }
-               $maxJobs = $this->getOption( 'maxjobs', 10000 );
+               $maxJobs = $this->getOption( 'maxjobs', false );
+               $maxTime = $this->getOption( 'maxtime', false );
+               $startTime = time();
                $type = $this->getOption( 'type', false );
                $wgTitle = Title::newFromText( 'RunJobs.php' );
                $dbw = wfGetDB( DB_MASTER );
@@ -71,7 +72,7 @@ class RunJobs extends Maintenance {
                                if ( !$job )
                                        break;
 
-                               wfWaitForSlaves( 5 );
+                               wfWaitForSlaves();
                                $t = microtime( true );
                                $offset = $job->id;
                                $status = $job->run();
@@ -82,14 +83,15 @@ class RunJobs extends Maintenance {
                                } else {
                                        $this->runJobsLog( $job->toString() . " t=$timeMs good" );
                                }
+
                                if ( $maxJobs && ++$n > $maxJobs ) {
                                        break 2;
                                }
+                               if ( $maxTime && time() - $startTime > $maxTime ) {
+                                       break 2;
+                               }
                        }
                }
-               if ( !$this->hasOption( 'procs' ) ) {
-                       $this->unlock();
-               }
        }
 
        /**
@@ -100,25 +102,6 @@ class RunJobs extends Maintenance {
                $this->output( wfTimestamp( TS_DB ) . " $msg\n" );
                wfDebugLog( 'runJobs', $msg );
        }
-
-       protected function lock() {
-               if ( $this->hasOption( 'exclusive' ) ) {
-                       $cache = wfGetCache( CACHE_ANYTHING );
-                       $running = $cache->get( wfMemcKey( 'runjobs' ) );
-                       if ( $running ) {
-                               return false;
-                       } else {
-                               $cache->set( wfMemcKey( 'runjobs' ), '1', 1800 );
-                               return true;
-                       }
-               }
-               return true;
-       }
-
-       protected function unlock() {
-               wfGetCache( CACHE_ANYTHING )->delete( wfMemcKey( 'runjobs' ) );
-       }
-
 }
 
 $maintClass = "RunJobs";