MediaWiki  REL1_24
runJobs.php
Go to the documentation of this file.
00001 <?php
00024 require_once __DIR__ . '/Maintenance.php';
00025 
00031 class RunJobs extends Maintenance {
00032     public function __construct() {
00033         parent::__construct();
00034         $this->mDescription = "Run pending jobs";
00035         $this->addOption( 'maxjobs', 'Maximum number of jobs to run', false, true );
00036         $this->addOption( 'maxtime', 'Maximum amount of wall-clock time', false, true );
00037         $this->addOption( 'type', 'Type of job to run', false, true );
00038         $this->addOption( 'procs', 'Number of processes to use', false, true );
00039         $this->addOption( 'nothrottle', 'Ignore job throttling configuration', false, false );
00040         $this->addOption( 'result', 'Set to JSON to print only a JSON response', false, true );
00041     }
00042 
00043     public function memoryLimit() {
00044         if ( $this->hasOption( 'memory-limit' ) ) {
00045             return parent::memoryLimit();
00046         }
00047 
00048         // Don't eat all memory on the machine if we get a bad job.
00049         return "150M";
00050     }
00051 
00052     public function execute() {
00053         if ( wfReadOnly() ) {
00054             $this->error( "Unable to run jobs; the wiki is in read-only mode.", 1 ); // die
00055         }
00056 
00057         if ( $this->hasOption( 'procs' ) ) {
00058             $procs = intval( $this->getOption( 'procs' ) );
00059             if ( $procs < 1 || $procs > 1000 ) {
00060                 $this->error( "Invalid argument to --procs", true );
00061             } elseif ( $procs != 1 ) {
00062                 $fc = new ForkController( $procs );
00063                 if ( $fc->start() != 'child' ) {
00064                     exit( 0 );
00065                 }
00066             }
00067         }
00068 
00069         $json = ( $this->getOption( 'result' ) === 'json' );
00070 
00071         $runner = new JobRunner();
00072         if ( !$json ) {
00073             $runner->setDebugHandler( array( $this, 'debugInternal' ) );
00074         }
00075         $response = $runner->run( array(
00076             'type'     => $this->getOption( 'type', false ),
00077             'maxJobs'  => $this->getOption( 'maxjobs', false ),
00078             'maxTime'  => $this->getOption( 'maxtime', false ),
00079             'throttle' => $this->hasOption( 'nothrottle' ) ? false : true,
00080         ) );
00081         if ( $json ) {
00082             $this->output( FormatJson::encode( $response, true ) );
00083         }
00084     }
00085 
00089     public function debugInternal( $s ) {
00090         $this->output( $s );
00091     }
00092 }
00093 
00094 $maintClass = "RunJobs";
00095 require_once RUN_MAINTENANCE_IF_MAIN;