2006-02-24 01:56:31 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
2012-08-11 20:48:09 +00:00
|
|
|
* Run pending jobs.
|
2008-07-19 12:15:07 +00:00
|
|
|
*
|
2009-08-02 19:35:17 +00:00
|
|
|
* 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
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-08-11 20:48:09 +00:00
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2006-02-24 01:56:31 +00:00
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2006-02-28 05:20:31 +00:00
|
|
|
|
2015-03-23 00:53:24 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
|
|
|
|
|
2017-10-09 17:10:13 +00:00
|
|
|
// So extensions (and other code) can check whether they're running in job mode
|
|
|
|
|
define( 'MEDIAWIKI_JOB_RUNNER', true );
|
|
|
|
|
|
2012-08-11 20:48:09 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script that runs pending jobs.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class RunJobs extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Run pending jobs' );
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->addOption( 'maxjobs', 'Maximum number of jobs to run', false, true );
|
2011-03-10 05:26:34 +00:00
|
|
|
$this->addOption( 'maxtime', 'Maximum amount of wall-clock time', false, true );
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->addOption( 'type', 'Type of job to run', false, true );
|
|
|
|
|
$this->addOption( 'procs', 'Number of processes to use', false, true );
|
2014-04-03 01:20:16 +00:00
|
|
|
$this->addOption( 'nothrottle', 'Ignore job throttling configuration', false, false );
|
2017-10-24 22:42:30 +00:00
|
|
|
$this->addOption( 'result', 'Set to "json" to print only a JSON response', false, true );
|
2016-02-20 20:22:58 +00:00
|
|
|
$this->addOption( 'wait', 'Wait for new jobs instead of exiting', false, false );
|
2009-02-19 07:15:19 +00:00
|
|
|
}
|
2010-04-17 17:09:11 +00:00
|
|
|
|
2009-09-14 22:10:10 +00:00
|
|
|
public function memoryLimit() {
|
2012-08-02 22:17:50 +00:00
|
|
|
if ( $this->hasOption( 'memory-limit' ) ) {
|
|
|
|
|
return parent::memoryLimit();
|
|
|
|
|
}
|
2014-04-23 18:09:26 +00:00
|
|
|
|
2009-09-14 22:10:10 +00:00
|
|
|
// Don't eat all memory on the machine if we get a bad job.
|
|
|
|
|
return "150M";
|
|
|
|
|
}
|
2009-06-24 02:49:24 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
|
|
|
|
if ( $this->hasOption( 'procs' ) ) {
|
2010-05-22 16:50:39 +00:00
|
|
|
$procs = intval( $this->getOption( 'procs' ) );
|
2009-08-02 19:35:17 +00:00
|
|
|
if ( $procs < 1 || $procs > 1000 ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Invalid argument to --procs" );
|
2013-04-17 21:23:05 +00:00
|
|
|
} elseif ( $procs != 1 ) {
|
|
|
|
|
$fc = new ForkController( $procs );
|
|
|
|
|
if ( $fc->start() != 'child' ) {
|
|
|
|
|
exit( 0 );
|
|
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2009-06-24 02:49:24 +00:00
|
|
|
}
|
2013-12-21 20:57:45 +00:00
|
|
|
|
2015-04-21 23:28:49 +00:00
|
|
|
$outputJSON = ( $this->getOption( 'result' ) === 'json' );
|
2016-02-20 20:22:58 +00:00
|
|
|
$wait = $this->hasOption( 'wait' );
|
2015-04-21 23:28:49 +00:00
|
|
|
|
2015-03-23 00:53:24 +00:00
|
|
|
$runner = new JobRunner( LoggerFactory::getInstance( 'runJobs' ) );
|
2015-04-21 23:28:49 +00:00
|
|
|
if ( !$outputJSON ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$runner->setDebugHandler( [ $this, 'debugInternal' ] );
|
2014-07-28 17:30:18 +00:00
|
|
|
}
|
2015-04-21 23:28:49 +00:00
|
|
|
|
2016-02-20 20:22:58 +00:00
|
|
|
$type = $this->getOption( 'type', false );
|
|
|
|
|
$maxJobs = $this->getOption( 'maxjobs', false );
|
|
|
|
|
$maxTime = $this->getOption( 'maxtime', false );
|
|
|
|
|
$throttle = !$this->hasOption( 'nothrottle' );
|
2015-04-21 23:28:49 +00:00
|
|
|
|
2016-02-20 20:22:58 +00:00
|
|
|
while ( true ) {
|
|
|
|
|
$response = $runner->run( [
|
|
|
|
|
'type' => $type,
|
|
|
|
|
'maxJobs' => $maxJobs,
|
|
|
|
|
'maxTime' => $maxTime,
|
|
|
|
|
'throttle' => $throttle,
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
if ( $outputJSON ) {
|
|
|
|
|
$this->output( FormatJson::encode( $response, true ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
!$wait ||
|
|
|
|
|
$response['reached'] === 'time-limit' ||
|
|
|
|
|
$response['reached'] === 'job-limit' ||
|
|
|
|
|
$response['reached'] === 'memory-limit'
|
|
|
|
|
) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $maxJobs !== false ) {
|
|
|
|
|
$maxJobs -= count( $response['jobs'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sleep( 1 );
|
2014-07-28 17:30:18 +00:00
|
|
|
}
|
2013-06-27 00:07:29 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
/**
|
2014-07-24 22:03:23 +00:00
|
|
|
* @param string $s
|
2009-08-02 19:35:17 +00:00
|
|
|
*/
|
2014-07-24 22:03:23 +00:00
|
|
|
public function debugInternal( $s ) {
|
|
|
|
|
$this->output( $s );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2009-02-16 04:50:26 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = RunJobs::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|