Go to the documentation of this file.
24 require_once __DIR__ .
'/Maintenance.php';
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 );
43 if ( $this->
hasOption(
'memory-limit' ) ) {
44 return parent::memoryLimit();
52 $this->
error(
"Unable to run jobs; the wiki is in read-only mode.", 1 );
56 $procs = intval( $this->
getOption(
'procs' ) );
57 if ( $procs < 1 || $procs > 1000 ) {
58 $this->
error(
"Invalid argument to --procs",
true );
59 } elseif ( $procs != 1 ) {
61 if ( $fc->start() !=
'child' ) {
68 $maxJobs = $this->
getOption(
'maxjobs',
false );
69 $maxTime = $this->
getOption(
'maxtime',
false );
70 $noThrottle = $this->
hasOption(
'nothrottle' );
75 $count = $group->executeReadyPeriodicTasks();
77 $this->
runJobsLog(
"Executed $count periodic queue task(s)." );
81 $startingBackoffs = $backoffs;
82 $backoffExpireFunc =
function(
$t ) {
return $t > time(); };
88 $backoffs = array_filter( $backoffs, $backoffExpireFunc );
89 $blacklist = $noThrottle ?
array() : array_keys( $backoffs );
90 if (
$type ===
false ) {
92 } elseif ( in_array(
$type, $blacklist ) ) {
102 set_time_limit( $maxTime ?: 0 );
105 $t = microtime(
true );
107 $status =
$job->run();
112 $error = get_class(
$e ) .
': ' .
$e->getMessage();
115 $timeMs = intval( ( microtime(
true ) -
$t ) * 1000 );
121 if ( $status !==
false || !
$job->allowRetries() ) {
125 if ( $status ===
false ) {
126 $this->
runJobsLog(
$job->toString() .
" t=$timeMs error={$error}" );
134 $jType =
$job->getType();
135 $backoffs[$jType] = isset( $backoffs[$jType] ) ? $backoffs[$jType] : 0;
136 $backoffs[$jType] = max( $backoffs[$jType], time() + $ttw );
140 if ( $maxJobs && $jobsRun >= $maxJobs ) {
142 } elseif ( $maxTime && ( time() - $startTime ) > $maxTime ) {
147 $timePassed = time() - $lastTime;
148 if ( $timePassed >= 5 || $timePassed < 0 ) {
153 if ( $jobsRun > 0 && ( $jobsRun % 100 ) == 0 ) {
154 $group->waitForBackups();
162 $backoffs = array_filter( $backoffs, $backoffExpireFunc );
163 if ( $backoffs !== $startingBackoffs ) {
174 global $wgJobBackoffThrottling;
176 if ( !isset( $wgJobBackoffThrottling[
$job->getType()] ) ) {
179 $itemsPerSecond = $wgJobBackoffThrottling[
$job->getType()];
180 if ( $itemsPerSecond <= 0 ) {
185 if (
$job->workItemCount() > 0 ) {
186 $seconds = floor(
$job->workItemCount() / $itemsPerSecond );
187 $remainder =
$job->workItemCount() % $itemsPerSecond;
188 $seconds += ( mt_rand( 1, $itemsPerSecond ) <= $remainder ) ? 1 : 0;
191 return (
int)$seconds;
204 if ( is_file(
$file ) ) {
205 $handle = fopen(
$file,
'rb' );
206 flock( $handle, LOCK_SH );
207 $content = stream_get_contents( $handle );
208 flock( $handle, LOCK_UN );
210 $backoffs = json_decode( $content,
true ) ?:
array();
225 $handle = fopen(
$file,
'wb+' );
226 flock( $handle, LOCK_EX );
227 $content = stream_get_contents( $handle );
228 $cBackoffs = json_decode( $content,
true ) ?:
array();
230 $cBackoffs[
$type] = isset( $cBackoffs[
$type] ) ? $cBackoffs[
$type] : 0;
233 ftruncate( $handle, 0 );
234 fwrite( $handle, json_encode( $backoffs ) );
235 flock( $handle, LOCK_UN );
245 static $maxBytes =
null;
246 if ( $maxBytes ===
null ) {
248 if ( preg_match(
'!^(\d+)(k|m|g|)$!i', ini_get(
'memory_limit' ), $m ) ) {
249 list( , $num, $unit ) = $m;
250 $conv =
array(
'g' => 1073741824,
'm' => 1048576,
'k' => 1024,
'' => 1 );
251 $maxBytes = $num * $conv[strtolower( $unit )];
256 $usedBytes = memory_get_usage();
257 if ( $maxBytes && $usedBytes >= 0.95 * $maxBytes ) {
258 throw new MWException(
"Detected excessive memory usage ($usedBytes/$maxBytes)." );
Maintenance script that runs pending jobs.
execute()
Do the actual work.
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
assertMemoryOK()
Make sure that this script is not too close to the memory usage limit.
Class for managing forking command line scripts.
memoryLimit()
Normally we disable the memory_limit when running admin scripts.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfDebugLog( $logGroup, $text, $dest='all')
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfProfileIn( $functionname)
Begin profiling of a function.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
require_once RUN_MAINTENANCE_IF_MAIN
wfReadOnly()
Check whether the wiki is in read-only mode.
const TS_DB
MySQL DATETIME (YYYY-MM-DD HH:MM:SS)
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Class to both describe a background job and handle jobs.
Class for handling function-scope profiling.
__construct()
Default constructor.
wfProfileOut( $functionname='missing')
Stop profiling of a function.
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
when a variable name is used in a it is silently declared as a new masking the global
wfWaitForSlaves( $maxLag=false, $wiki=false, $cluster=false)
Modern version of wfWaitForSlaves().
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
if(PHP_SAPI !='cli') $file
getBackoffTimeToWait(Job $job)
wfTempDir()
Tries to get the system directory for temporary files.
getOption( $name, $default=null)
Get an option, or return the default.
if(count( $args)< 1) $job
static rollbackMasterChangesAndLog(Exception $e)
If there are any open database transactions, roll them back and log the stack trace of the exception ...
static singleton( $wiki=false)
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
runJobsLog( $msg)
Log the job message.
syncBackoffs(array $backoffs)
Merge the current backoff expiries from persistent storage.
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead where the first element is the message key and the remaining elements are used as parameters to the message based on mime etc Preferred in most cases over UploadVerification object with all info about the upload string as detected by MediaWiki Handlers will typically only apply for specific mime types object & $error
hasOption( $name)
Checks to see if a particular param exists.
loadBackoffs()
Get the previous backoff expiries from persistent storage.