MediaWiki master
JobRunner Class Reference

Job queue runner utility methods. More...

Public Member Functions

 __construct (ServiceOptions $serviceOptions, ILBFactory $lbFactory, JobQueueGroup $jobQueueGroup, ReadOnlyMode $readOnlyMode, LinkCache $linkCache, StatsdDataFactoryInterface $statsdDataFactory, LoggerInterface $logger)
 
 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)
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

Detailed Description

Job queue runner utility methods.

Since
1.24

Definition at line 39 of file JobRunner.php.

Constructor & Destructor Documentation

◆ __construct()

JobRunner::__construct ( ServiceOptions $serviceOptions,
ILBFactory $lbFactory,
JobQueueGroup $jobQueueGroup,
ReadOnlyMode $readOnlyMode,
LinkCache $linkCache,
StatsdDataFactoryInterface $statsdDataFactory,
LoggerInterface $logger )
Access: internal
For use by ServiceWiring
Parameters
ServiceOptions$serviceOptions
ILBFactory$lbFactory
JobQueueGroup$jobQueueGroupThe JobQueueGroup for this wiki
ReadOnlyMode$readOnlyMode
LinkCache$linkCache
StatsdDataFactoryInterface$statsdDataFactory
LoggerInterface$logger

Definition at line 103 of file JobRunner.php.

References MediaWiki\Config\ServiceOptions\assertRequiredOptions().

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 $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 314 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 147 of file JobRunner.php.

References $job, and executeJob().

◆ setDebugHandler()

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

Definition at line 89 of file JobRunner.php.

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

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

Definition at line 44 of file JobRunner.php.


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