* @since 1.21
*/
abstract class JobQueue {
- /** @var string Wiki ID */
+ /** @var string DB domain ID */
protected $domain;
/** @var string Job type */
protected $type;
/**
* @param array $params
- * @throws MWException
+ * @throws JobQueueError
*/
protected function __construct( array $params ) {
$this->domain = $params['domain'] ?? $params['wiki']; // b/c
$this->order = $this->optimalOrder();
}
if ( !in_array( $this->order, $this->supportedOrders() ) ) {
- throw new MWException( __CLASS__ . " does not support '{$this->order}' order." );
+ throw new JobQueueError( __CLASS__ . " does not support '{$this->order}' order." );
}
$this->dupCache = wfGetCache( CACHE_ANYTHING );
$this->aggr = $params['aggregator'] ?? new JobQueueAggregatorNull( [] );
*
* @param array $params
* @return JobQueue
- * @throws MWException
+ * @throws JobQueueError
*/
final public static function factory( array $params ) {
$class = $params['class'];
if ( !class_exists( $class ) ) {
- throw new MWException( "Invalid job queue class '$class'." );
+ throw new JobQueueError( "Invalid job queue class '$class'." );
}
$obj = new $class( $params );
if ( !( $obj instanceof self ) ) {
- throw new MWException( "Class '$class' is not a " . __CLASS__ . " class." );
+ throw new JobQueueError( "Class '$class' is not a " . __CLASS__ . " class." );
}
return $obj;
* @param IJobSpecification[] $jobs
* @param int $flags Bitfield (supports JobQueue::QOS_ATOMIC)
* @return void
- * @throws MWException
+ * @throws JobQueueError
*/
final public function batchPush( array $jobs, $flags = 0 ) {
$this->assertNotReadOnly();
foreach ( $jobs as $job ) {
if ( $job->getType() !== $this->type ) {
- throw new MWException(
+ throw new JobQueueError(
"Got '{$job->getType()}' job; expected a '{$this->type}' job." );
} elseif ( $job->getReleaseTimestamp() && !$this->supportsDelayedJobs() ) {
- throw new MWException(
+ throw new JobQueueError(
"Got delayed '{$job->getType()}' job; delays are not supported." );
}
}
* This requires $wgJobClasses to be set for the given job type.
* Outside callers should use JobQueueGroup::pop() instead of this function.
*
- * @throws MWException
+ * @throws JobQueueError
* @return Job|bool Returns false if there are no jobs
*/
final public function pop() {
$this->assertNotReadOnly();
if ( !WikiMap::isCurrentWikiDbDomain( $this->domain ) ) {
- throw new MWException(
+ throw new JobQueueError(
"Cannot pop '{$this->type}' job off foreign '{$this->domain}' wiki queue." );
} elseif ( !isset( $wgJobClasses[$this->type] ) ) {
// Do not pop jobs if there is no class for the queue type
- throw new MWException( "Unrecognized job type '{$this->type}'." );
+ throw new JobQueueError( "Unrecognized job type '{$this->type}'." );
}
$job = $this->doPop();
*
* @param Job $job
* @return void
- * @throws MWException
+ * @throws JobQueueError
*/
final public function ack( Job $job ) {
$this->assertNotReadOnly();
if ( $job->getType() !== $this->type ) {
- throw new MWException( "Got '{$job->getType()}' job; expected '{$this->type}'." );
+ throw new JobQueueError( "Got '{$job->getType()}' job; expected '{$this->type}'." );
}
$this->doAck( $job );
* This does nothing for certain queue classes.
*
* @param IJobSpecification $job
- * @throws MWException
+ * @throws JobQueueError
* @return bool
*/
final public function deduplicateRootJob( IJobSpecification $job ) {
$this->assertNotReadOnly();
if ( $job->getType() !== $this->type ) {
- throw new MWException( "Got '{$job->getType()}' job; expected '{$this->type}'." );
+ throw new JobQueueError( "Got '{$job->getType()}' job; expected '{$this->type}'." );
}
return $this->doDeduplicateRootJob( $job );
/**
* @see JobQueue::deduplicateRootJob()
* @param IJobSpecification $job
- * @throws MWException
+ * @throws JobQueueError
* @return bool
*/
protected function doDeduplicateRootJob( IJobSpecification $job ) {
if ( !$job->hasRootJobParams() ) {
- throw new MWException( "Cannot register root job; missing parameters." );
+ throw new JobQueueError( "Cannot register root job; missing parameters." );
}
$params = $job->getRootJobParams();
* Check if the "root" job of a given job has been superseded by a newer one
*
* @param Job $job
- * @throws MWException
+ * @throws JobQueueError
* @return bool
*/
final protected function isRootJobOldDuplicate( Job $job ) {
if ( $job->getType() !== $this->type ) {
- throw new MWException( "Got '{$job->getType()}' job; expected '{$this->type}'." );
+ throw new JobQueueError( "Got '{$job->getType()}' job; expected '{$this->type}'." );
}
$isDuplicate = $this->doIsRootJobOldDuplicate( $job );
/**
* @see JobQueue::delete()
- * @throws MWException
+ * @throws JobQueueError
*/
protected function doDelete() {
- throw new MWException( "This method is not implemented." );
+ throw new JobQueueError( "This method is not implemented." );
}
/**
*
* @param array $types List of queues types
* @return array|null (list of non-empty queue types) or null if unsupported
- * @throws MWException
+ * @throws JobQueueError
* @since 1.22
*/
final public function getSiblingQueuesWithJobs( array $types ) {
*
* @param array $types List of queues types
* @return array|null (job type => whether queue is empty) or null if unsupported
- * @throws MWException
+ * @throws JobQueueError
* @since 1.22
*/
final public function getSiblingQueueSizes( array $types ) {
/**
* Get the list of job types that have non-empty queues
*
- * @return array List of job types that have non-empty queues
+ * @return string[] List of job types that have non-empty queues
*/
public function getQueuesWithJobs() {
$types = [];
foreach ( $this->getCoalescedQueues() as $info ) {
- $nonEmpty = $info['queue']->getSiblingQueuesWithJobs( $this->getQueueTypes() );
+ /** @var JobQueue $queue */
+ $queue = $info['queue'];
+ $nonEmpty = $queue->getSiblingQueuesWithJobs( $this->getQueueTypes() );
if ( is_array( $nonEmpty ) ) { // batching features supported
$types = array_merge( $types, $nonEmpty );
} else { // we have to go through the queues in the bucket one-by-one
/**
* Get the size of the queus for a list of job types
*
- * @return array Map of (job type => size)
+ * @return int[] Map of (job type => size)
*/
public function getQueueSizes() {
$sizeMap = [];
foreach ( $this->getCoalescedQueues() as $info ) {
- $sizes = $info['queue']->getSiblingQueueSizes( $this->getQueueTypes() );
+ /** @var JobQueue $queue */
+ $queue = $info['queue'];
+ $sizes = $queue->getSiblingQueueSizes( $this->getQueueTypes() );
if ( is_array( $sizes ) ) { // batching features supported
$sizeMap = $sizeMap + $sizes;
} else { // we have to go through the queues in the bucket one-by-one
}
/**
- * @return array
+ * @return JobQueue[]
*/
protected function getCoalescedQueues() {
global $wgJobTypeConf;