MediaWiki REL1_39
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
 

Detailed Description

Job queue runner utility methods.

Since
1.24

Definition at line 43 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 119 of file JobRunner.php.

References wfDeprecated().

Member Function Documentation

◆ 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 338 of file JobRunner.php.

References $job.

Referenced by run().

◆ 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, exception)

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 171 of file JobRunner.php.

References $job, $type, and executeJob().

◆ setDebugHandler()

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

Definition at line 94 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 103 of file JobRunner.php.

References wfDeprecated().

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const JobRunner::CONSTRUCTOR_OPTIONS
Initial value:
= [
MainConfigNames::JobBackoffThrottling,
MainConfigNames::JobClasses,
MainConfigNames::JobSerialCommitThreshold,
MainConfigNames::MaxJobDBWriteDuration,
MainConfigNames::TrxProfilerLimits,
]
Access: internal
For use by ServiceWiring

Definition at line 48 of file JobRunner.php.


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