5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup Maintenance
24 require_once __DIR__
. '/Maintenance.php';
27 * Maintenance script that runs pending jobs.
29 * @ingroup Maintenance
31 class RunJobs
extends Maintenance
{
32 public function __construct() {
33 parent
::__construct();
34 $this->mDescription
= "Run pending jobs";
35 $this->addOption( 'maxjobs', 'Maximum number of jobs to run', false, true );
36 $this->addOption( 'maxtime', 'Maximum amount of wall-clock time', false, true );
37 $this->addOption( 'type', 'Type of job to run', false, true );
38 $this->addOption( 'procs', 'Number of processes to use', false, true );
39 $this->addOption( 'nothrottle', 'Ignore job throttling configuration', false, false );
40 $this->addOption( 'result', 'Set to JSON to print only a JSON response', false, true );
43 public function memoryLimit() {
44 if ( $this->hasOption( 'memory-limit' ) ) {
45 return parent
::memoryLimit();
48 // Don't eat all memory on the machine if we get a bad job.
52 public function execute() {
54 $this->error( "Unable to run jobs; the wiki is in read-only mode.", 1 ); // die
57 if ( $this->hasOption( 'procs' ) ) {
58 $procs = intval( $this->getOption( 'procs' ) );
59 if ( $procs < 1 ||
$procs > 1000 ) {
60 $this->error( "Invalid argument to --procs", true );
61 } elseif ( $procs != 1 ) {
62 $fc = new ForkController( $procs );
63 if ( $fc->start() != 'child' ) {
69 $json = ( $this->getOption( 'result' ) === 'json' );
71 $runner = new JobRunner();
73 $runner->setDebugHandler( array( $this, 'debugInternal' ) );
75 $response = $runner->run( array(
76 'type' => $this->getOption( 'type', false ),
77 'maxJobs' => $this->getOption( 'maxjobs', false ),
78 'maxTime' => $this->getOption( 'maxtime', false ),
79 'throttle' => $this->hasOption( 'nothrottle' ) ?
false : true,
82 $this->output( FormatJson
::encode( $response, true ) );
89 public function debugInternal( $s ) {
94 $maintClass = "RunJobs";
95 require_once RUN_MAINTENANCE_IF_MAIN
;