79 if ( self::$executeContext && self::$executeContext[
'stage'] >= $stage ) {
83 self::$executeContext[
'subqueue'][] = $update;
88 if ( $stage === self::PRESEND ) {
89 self::push( self::$preSendUpdates, $update );
91 self::push( self::$postSendUpdates, $update );
97 self::tryOpportunisticExecute(
'run' );
112 $callable, $stage = self::POSTSEND, $dbw =
null
123 public static function doUpdates( $mode =
'run', $stage = self::ALL ) {
124 $stageEffective = ( $stage === self::ALL ) ? self::POSTSEND : $stage;
126 if ( $stage === self::ALL || $stage === self::PRESEND ) {
127 self::execute( self::$preSendUpdates, $mode, $stageEffective );
130 if ( $stage === self::ALL || $stage == self::POSTSEND ) {
131 self::execute( self::$postSendUpdates, $mode, $stageEffective );
150 $class = get_class( $update );
151 if ( isset(
$queue[$class] ) ) {
153 $existingUpdate =
$queue[$class];
154 $existingUpdate->merge( $update );
173 $services = MediaWikiServices::getInstance();
174 $stats =
$services->getStatsdDataFactory();
175 $lbFactory =
$services->getDBLoadBalancerFactory();
178 $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
181 $reportableError =
null;
190 $updatesByType = [
'data' => [],
'generic' => [] ];
191 foreach ( $updates as $du ) {
193 $du->setTransactionTicket( $ticket );
194 $updatesByType[
'data'][] = $du;
196 $updatesByType[
'generic'][] = $du;
200 ? get_class( $du ) .
'-' . $du->getOrigin()
202 $stats->increment(
'deferred_updates.' . $method .
'.' . $name );
206 foreach ( $updatesByType as $updatesForType ) {
207 foreach ( $updatesForType as $update ) {
208 self::$executeContext = [
'stage' => $stage,
'subqueue' => [] ];
210 $guiError = self::runUpdate( $update, $lbFactory, $mode, $stage );
211 $reportableError = $reportableError ?: $guiError;
213 while ( self::$executeContext[
'subqueue'] ) {
214 $subUpdate = reset( self::$executeContext[
'subqueue'] );
215 $firstKey =
key( self::$executeContext[
'subqueue'] );
216 unset( self::$executeContext[
'subqueue'][$firstKey] );
219 $subUpdate->setTransactionTicket( $ticket );
222 $guiError = self::runUpdate( $subUpdate, $lbFactory, $mode, $stage );
223 $reportableError = $reportableError ?: $guiError;
225 self::$executeContext =
null;
232 if ( $reportableError ) {
233 throw $reportableError;
251 $spec = $update->getAsJobSpecification();
257 $fnameTrxOwner = get_class( $update ) .
'::doUpdate';
258 $lbFactory->beginMasterChanges( $fnameTrxOwner );
260 $lbFactory->commitMasterChanges( $fnameTrxOwner );
262 }
catch ( Exception
$e ) {
267 MWExceptionHandler::rollbackMasterChangesAndLog(
$e );
285 if ( self::$executeContext ) {
290 if ( !self::areDatabaseTransactionsActive() ) {
291 self::doUpdates( $mode );
295 if ( self::pendingUpdatesCount() >= self::BIG_QUEUE_SIZE ) {
298 self::$preSendUpdates = self::enqueueUpdates( self::$preSendUpdates );
299 self::$postSendUpdates = self::enqueueUpdates( self::$postSendUpdates );
302 return !self::pendingUpdatesCount();
314 foreach ( $updates as $update ) {
316 $spec = $update->getAsJobSpecification();
319 $remaining[] = $update;
331 return count( self::$preSendUpdates ) + count( self::$postSendUpdates );
341 if ( $stage === self::ALL || $stage === self::PRESEND ) {
342 $updates = array_merge( $updates, self::$preSendUpdates );
344 if ( $stage === self::ALL || $stage === self::POSTSEND ) {
345 $updates = array_merge( $updates, self::$postSendUpdates );
355 self::$preSendUpdates = [];
356 self::$postSendUpdates = [];
363 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
364 if ( $lbFactory->hasTransactionRound() ) {
369 $lbFactory->forEachLB(
function (
LoadBalancer $lb ) use ( &$connsBusy ) {
global $wgCommandLineMode
wfGetCaller( $level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Abstract base class for update jobs that do something with some secondary data extracted from article...
Class for managing the deferred updates.
static enqueueUpdates(array $updates)
Enqueue a job for each EnqueueableDataUpdate item and return the other items.
static runUpdate(DeferrableUpdate $update, LBFactory $lbFactory, $mode, $stage)
static doUpdates( $mode='run', $stage=self::ALL)
Do any deferred updates and clear the list.
static areDatabaseTransactionsActive()
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred list to be run later by execute()
static pendingUpdatesCount()
static tryOpportunisticExecute( $mode='run')
Run all deferred updates immediately if there are no DB writes active.
static push(array &$queue, DeferrableUpdate $update)
static clearPendingUpdates()
Clear all pending updates without performing them.
static setImmediateMode( $value)
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add a callable update.
static array null $executeContext
Information about the current execute() call or null if not running.
static DeferrableUpdate[] $preSendUpdates
Updates to be deferred until before request end.
static execute(array &$queue, $mode, $stage)
Immediately run/queue a list of updates.
static DeferrableUpdate[] $postSendUpdates
Updates to be deferred until after request end.
static getPendingUpdates( $stage=self::ALL)
An error page which can definitely be safely rendered using the OutputPage.
static singleton( $domain=false)
Deferrable Update for closure/callback.
static getMain()
Get the RequestContext object associated with the main request.
Deferrable update that must run outside of any explicit LBFactory transaction round.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
returning false will NOT prevent logging $e
Callback wrapper that has an originating method.
Interface that deferrable updates should implement.
Interface that marks a DataUpdate as enqueuable via the JobQueue.
Interface that deferrable updates can implement.