11require_once __DIR__ .
'/Maintenance.php';
26 parent::__construct();
28 $this->
addOption(
'maxjobs',
'Maximum number of jobs to run',
false,
true );
29 $this->
addOption(
'maxtime',
'Maximum amount of wall-clock time',
false,
true );
30 $this->
addOption(
'type',
'Type of job to run',
false,
true );
31 $this->
addOption(
'procs',
'Number of processes to use',
false,
true );
32 $this->
addOption(
'nothrottle',
'Ignore job throttling configuration',
false,
false );
33 $this->
addOption(
'result',
'Set to "json" to print only a JSON response',
false,
true );
34 $this->
addOption(
'wait',
'Wait for new jobs instead of exiting',
false,
false );
40 define(
'MEDIAWIKI_JOB_RUNNER',
true );
41 parent::finalSetup( $settingsBuilder );
46 if ( $this->
hasOption(
'memory-limit' ) ) {
47 return parent::memoryLimit();
59 return $limit === -1 ? $limit : ( $limit * 3 );
64 $procs = intval( $this->
getOption(
'procs' ) );
65 if ( $procs < 1 || $procs > 1000 ) {
66 $this->
fatalError(
"Invalid argument to --procs" );
67 } elseif ( $procs != 1 ) {
70 }
catch ( Throwable $e ) {
73 if ( $fc->start() !=
'child' ) {
79 $outputJSON = ( $this->
getOption(
'result' ) ===
'json' );
84 $runner->setDebugHandler( $this->debugInternal( ... ) );
87 $type = $this->
getOption(
'type',
false );
88 $maxJobs = $this->
getOption(
'maxjobs',
false );
89 $maxTime = $this->
getOption(
'maxtime',
false );
90 $throttle = !$this->
hasOption(
'nothrottle' );
95 'maxJobs' => $maxJobs,
96 'maxTime' => $maxTime,
97 'throttle' => $throttle,
101 $this->
output( FormatJson::encode( $response,
true ) );
106 $response[
'reached'] ===
'time-limit' ||
107 $response[
'reached'] ===
'job-limit' ||
108 $response[
'reached'] ===
'memory-limit' ||
109 $response[
'reached'] ===
'exception'
112 if ( !$outputJSON && $response[
'jobs'] === [] ) {
113 $this->
output(
"Job queue is empty.\n" );
118 if ( $maxJobs !==
false ) {
119 $maxJobs -= count( $response[
'jobs'] );
129 private function debugInternal( $s ) {
136require_once RUN_MAINTENANCE_IF_MAIN;
wfShorthandToInteger(?string $string='', int $default=-1)
Converts shorthand byte notation to integer form.
Manage forking inside CLI maintenance scripts.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Maintenance script that runs pending jobs.
execute()
Do the actual work.
memoryLimit()
Override memory_limit from php.ini on maintenance scripts.This defaults to max/unlimited,...
__construct()
Default constructor.
finalSetup(SettingsBuilder $settingsBuilder)
Handle some last-minute setup here.
$wgMemoryLimit
Config variable stub for the MemoryLimit setting, for use by phpdoc and IDEs.