25require_once __DIR__ .
'/Maintenance.php';
40 parent::__construct();
42 $this->
addOption(
'maxjobs',
'Maximum number of jobs to run',
false,
true );
43 $this->
addOption(
'maxtime',
'Maximum amount of wall-clock time',
false,
true );
44 $this->
addOption(
'type',
'Type of job to run',
false,
true );
45 $this->
addOption(
'procs',
'Number of processes to use',
false,
true );
46 $this->
addOption(
'nothrottle',
'Ignore job throttling configuration',
false,
false );
47 $this->
addOption(
'result',
'Set to "json" to print only a JSON response',
false,
true );
48 $this->
addOption(
'wait',
'Wait for new jobs instead of exiting',
false,
false );
54 define(
'MEDIAWIKI_JOB_RUNNER',
true );
55 parent::finalSetup( $settingsBuilder );
59 if ( $this->
hasOption(
'memory-limit' ) ) {
60 return parent::memoryLimit();
69 $procs = intval( $this->
getOption(
'procs' ) );
70 if ( $procs < 1 || $procs > 1000 ) {
71 $this->
fatalError(
"Invalid argument to --procs" );
72 } elseif ( $procs != 1 ) {
75 }
catch ( Throwable $e ) {
78 if ( $fc->start() !=
'child' ) {
84 $outputJSON = ( $this->
getOption(
'result' ) ===
'json' );
89 $runner->setDebugHandler( [ $this,
'debugInternal' ] );
92 $type = $this->
getOption(
'type',
false );
93 $maxJobs = $this->
getOption(
'maxjobs',
false );
94 $maxTime = $this->
getOption(
'maxtime',
false );
95 $throttle = !$this->
hasOption(
'nothrottle' );
100 'maxJobs' => $maxJobs,
101 'maxTime' => $maxTime,
102 'throttle' => $throttle,
106 $this->
output( FormatJson::encode( $response,
true ) );
111 $response[
'reached'] ===
'time-limit' ||
112 $response[
'reached'] ===
'job-limit' ||
113 $response[
'reached'] ===
'memory-limit' ||
114 $response[
'reached'] ===
'exception'
117 if ( !$outputJSON && $response[
'jobs'] === [] ) {
118 $this->
output(
"Job queue is empty.\n" );
123 if ( $maxJobs !==
false ) {
124 $maxJobs -= count( $response[
'jobs'] );
141require_once RUN_MAINTENANCE_IF_MAIN;
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()
Normally we disable the memory_limit when running admin scripts.
__construct()
Default constructor.
finalSetup(SettingsBuilder $settingsBuilder)
Handle some last-minute setup here.