MediaWiki fundraising/REL1_35
JobRunner Class Reference

Job queue runner utility methods. More...

Inheritance diagram for JobRunner:
Collaboration diagram for JobRunner:

Public Member Functions

 __construct ( $serviceOptions=null, ILBFactory $lbFactory=null, JobQueueGroup $jobQueueGroup=null, ReadOnlyMode $readOnlyMode=null, LinkCache $linkCache=null, StatsdDataFactoryInterface $statsdDataFactory=null, LoggerInterface $logger=null)
 Calling this directly is deprecated.
 
 executeJob (RunnableJob $job)
 Run a specific job in a manner appropriate for mass use by job dispatchers.
 
 run (array $options)
 Run jobs of the specified number/type for the specified time.
 
 setDebugHandler ( $debug)
 
 setLogger (LoggerInterface $logger)
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

Private Member Functions

 checkMemoryOK ()
 Make sure that this script is not too close to the memory usage limit.
 
 commitMasterChanges (RunnableJob $job, $fnameTrxOwner)
 Issue a commit on all masters who are currently in a transaction and have made changes to the database.
 
 debugCallback ( $msg)
 Log the job message.
 
 doExecuteJob (RunnableJob $job)
 
 getBackoffTimeToWait (RunnableJob $job)
 
 getErrorBackoffTTL (array $caught)
 
 getMaxRssKb ()
 
 loadBackoffs (array $backoffs, $mode='wait')
 Get the previous backoff expiries from persistent storage On I/O or lock acquisition failure this returns the original $backoffs.
 
 syncBackoffDeltas (array $backoffs, array &$deltas, $mode='wait')
 Merge the current backoff expiries from persistent storage.
 

Private Attributes

callable null $debug
 Debug output handler.
 
JobQueueGroup $jobQueueGroup
 
ILBFactory $lbFactory
 
LinkCache $linkCache
 
LoggerInterface $logger
 
ServiceOptions $options
 
ReadOnlyMode $readOnlyMode
 
StatsdDataFactoryInterface $stats
 

Detailed Description

Job queue runner utility methods.

Since
1.24

Definition at line 41 of file JobRunner.php.

Constructor & Destructor Documentation

◆ __construct()

JobRunner::__construct ( $serviceOptions = null,
ILBFactory $lbFactory = null,
JobQueueGroup $jobQueueGroup = null,
ReadOnlyMode $readOnlyMode = null,
LinkCache $linkCache = null,
StatsdDataFactoryInterface $statsdDataFactory = null,
LoggerInterface $logger = null )

Calling this directly is deprecated.

Obtain an instance via MediaWikiServices instead.

Parameters
ServiceOptions | LoggerInterface | null$serviceOptions
ILBFactory | null$lbFactory
JobQueueGroup | null$jobQueueGroupThe JobQueueGroup for this wiki
ReadOnlyMode | null$readOnlyMode
LinkCache | null$linkCache
StatsdDataFactoryInterface | null$statsdDataFactory
LoggerInterface | null$logger

Definition at line 114 of file JobRunner.php.

References $jobQueueGroup, $lbFactory, $linkCache, $logger, and $readOnlyMode.

Member Function Documentation

◆ checkMemoryOK()

JobRunner::checkMemoryOK ( )
private

Make sure that this script is not too close to the memory usage limit.

It is better to die in between jobs than OOM right in the middle of one.

Returns
bool

Definition at line 576 of file JobRunner.php.

References debugCallback().

Referenced by run().

◆ commitMasterChanges()

JobRunner::commitMasterChanges ( RunnableJob $job,
$fnameTrxOwner )
private

Issue a commit on all masters who are currently in a transaction and have made changes to the database.

It also supports sometimes waiting for the local wiki's replica DBs to catch up. See the documentation for $wgJobSerialCommitThreshold for more.

Parameters
RunnableJob$job
string$fnameTrxOwner
Exceptions
DBError

Definition at line 625 of file JobRunner.php.

References $job, and debugCallback().

Referenced by doExecuteJob().

◆ debugCallback()

JobRunner::debugCallback ( $msg)
private

Log the job message.

Parameters
string$msgThe message to log

Definition at line 609 of file JobRunner.php.

References wfTimestamp().

Referenced by checkMemoryOK(), commitMasterChanges(), and doExecuteJob().

◆ doExecuteJob()

JobRunner::doExecuteJob ( RunnableJob $job)
private
Parameters
RunnableJob$job
Returns
array Map of:
  • status: boolean; whether the job succeed
  • error: error string; empty if there was no error specified
  • caught: list of FQCNs corresponding to any exceptions caught
  • timeMs: float; job execution time in milliseconds

Definition at line 348 of file JobRunner.php.

References $job, commitMasterChanges(), debugCallback(), getMaxRssKb(), and wfTimestamp().

Referenced by executeJob().

◆ executeJob()

JobRunner::executeJob ( RunnableJob $job)

Run a specific job in a manner appropriate for mass use by job dispatchers.

Wraps the job's run() and tearDown() methods into appropriate transaction rounds. During execution, SPI-based logging will use the ID of the HTTP request that spawned the job (instead of the current one). Large DB write transactions will be subject to $wgJobSerialCommitThreshold and $wgMaxJobDBWriteDuration.

This should never be called if there are explicit transaction rounds or pending DB writes

Parameters
RunnableJob$job
Returns
array Map of:
  • status: boolean; whether the job succeed
  • error: error string; empty if there was no error specified
  • caught: list of FQCNs corresponding to any exceptions caught
  • timeMs: float; job execution time in milliseconds
Since
1.35

Definition at line 326 of file JobRunner.php.

References $job, and doExecuteJob().

Referenced by run().

◆ getBackoffTimeToWait()

JobRunner::getBackoffTimeToWait ( RunnableJob $job)
private
Parameters
RunnableJob$job
Returns
int Seconds for this runner to avoid doing more jobs of this type
See also
$wgJobBackoffThrottling

Definition at line 467 of file JobRunner.php.

References $job.

Referenced by run().

◆ getErrorBackoffTTL()

JobRunner::getErrorBackoffTTL ( array $caught)
private
Parameters
string[]$caughtList of FQCNs corresponding to any exceptions caught
Returns
int TTL in seconds

Definition at line 447 of file JobRunner.php.

Referenced by run().

◆ getMaxRssKb()

JobRunner::getMaxRssKb ( )
private
Returns
int|null Max memory RSS in kilobytes

Definition at line 456 of file JobRunner.php.

Referenced by doExecuteJob().

◆ loadBackoffs()

JobRunner::loadBackoffs ( array $backoffs,
$mode = 'wait' )
private

Get the previous backoff expiries from persistent storage On I/O or lock acquisition failure this returns the original $backoffs.

Parameters
array$backoffsMap of (job type => UNIX timestamp)
string$modeLock wait mode - "wait" or "nowait"
Returns
array Map of (job type => backoff expiry timestamp)

Definition at line 499 of file JobRunner.php.

References $content, $file, $type, and wfTempDir().

Referenced by syncBackoffDeltas().

◆ run()

JobRunner::run ( array $options)

Run jobs of the specified number/type for the specified time.

The response map has a 'job' field that lists status of each job, including:

  • type : the job/queue type
  • status : ok/failed
  • error : any error message string
  • time : the job run time in ms The response map also has:
  • backoffs : the (job/queue type => seconds) map of backoff times
  • elapsed : the total time spent running tasks in ms
  • reached : the reason the script finished, one of (none-ready, job-limit, time-limit, memory-limit)

This method outputs status information only if a debug handler was set. Any exceptions are caught and logged, but are not reported as output.

Parameters
array$optionsMap of parameters:
  • type : specified job/queue type (or false for the default types)
  • maxJobs : maximum number of jobs to run
  • maxTime : maximum time in seconds before stopping
  • throttle : whether to respect job backoff configuration
Returns
array Summary response that can easily be JSON serialized
Exceptions
JobQueueError

Definition at line 166 of file JobRunner.php.

References $job, $type, checkMemoryOK(), executeJob(), getBackoffTimeToWait(), getErrorBackoffTTL(), and syncBackoffDeltas().

◆ setDebugHandler()

JobRunner::setDebugHandler ( $debug)
Parameters
callable$debugOptional debug output handler

Definition at line 89 of file JobRunner.php.

References $debug.

◆ setLogger()

JobRunner::setLogger ( LoggerInterface $logger)
Parameters
LoggerInterface$logger
Returns
void
Deprecated
since 1.35. Rely on the logger passed in the constructor.

Definition at line 98 of file JobRunner.php.

References wfDeprecated().

◆ syncBackoffDeltas()

JobRunner::syncBackoffDeltas ( array $backoffs,
array & $deltas,
$mode = 'wait' )
private

Merge the current backoff expiries from persistent storage.

The $deltas map is set to an empty array on success. On I/O or lock acquisition failure this returns the original $backoffs.

Parameters
array$backoffsMap of (job type => UNIX timestamp)
array&$deltasMap of (job type => seconds)
string$modeLock wait mode - "wait" or "nowait"
Returns
array The new backoffs account for $backoffs and the latest file data

Definition at line 536 of file JobRunner.php.

References $content, $file, $type, loadBackoffs(), and wfTempDir().

Referenced by run().

Member Data Documentation

◆ $debug

callable null JobRunner::$debug
private

Debug output handler.

Definition at line 70 of file JobRunner.php.

◆ $jobQueueGroup

JobQueueGroup JobRunner::$jobQueueGroup
private

Definition at line 58 of file JobRunner.php.

Referenced by __construct().

◆ $lbFactory

ILBFactory JobRunner::$lbFactory
private

Definition at line 55 of file JobRunner.php.

Referenced by __construct().

◆ $linkCache

LinkCache JobRunner::$linkCache
private

Definition at line 64 of file JobRunner.php.

Referenced by __construct().

◆ $logger

LoggerInterface JobRunner::$logger
private

Definition at line 73 of file JobRunner.php.

Referenced by __construct().

◆ $options

ServiceOptions JobRunner::$options
private

Definition at line 52 of file JobRunner.php.

◆ $readOnlyMode

ReadOnlyMode JobRunner::$readOnlyMode
private

Definition at line 61 of file JobRunner.php.

Referenced by __construct().

◆ $stats

StatsdDataFactoryInterface JobRunner::$stats
private

Definition at line 67 of file JobRunner.php.

◆ CONSTRUCTOR_OPTIONS

const JobRunner::CONSTRUCTOR_OPTIONS
Initial value:
= [
'JobBackoffThrottling',
'JobClasses',
'JobSerialCommitThreshold',
'MaxJobDBWriteDuration',
'TrxProfilerLimits'
]

Definition at line 43 of file JobRunner.php.


The documentation for this class was generated from the following file: