* @since 1.21
*/
abstract class JobQueue {
- /** @var string Wiki ID */
+ /** @var string DB domain ID */
protected $domain;
/** @var string Job type */
protected $type;
/** @var BagOStuff */
protected $dupCache;
- /** @var JobQueueAggregator */
- protected $aggr;
const QOS_ATOMIC = 1; // integer; "all-or-nothing" job insertions
/**
* @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( [] );
$this->readOnlyReason = $params['readOnlyReason'] ?? false;
}
* Get a job queue object of the specified type.
* $params includes:
* - class : What job class to use (determines job type)
- * - wiki : wiki ID of the wiki the jobs are for (defaults to current wiki)
+ * - domain : Database domain ID of the wiki the jobs are for (defaults to current wiki)
* - type : The name of the job types this queue handles
* - order : Order that pop() selects jobs, one of "fifo", "timestamp" or "random".
* If "fifo" is used, the queue will effectively be FIFO. Note that job
*
* @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;
* @deprecated 1.33
*/
final public function getWiki() {
- return $this->domain;
+ return WikiMap::getWikiIdFromDbDomain( $this->domain );
}
/**
* @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->doBatchPush( $jobs, $flags );
- $this->aggr->notifyQueueNonEmpty( $this->domain, $this->type );
foreach ( $jobs as $job ) {
if ( $job->isRootJob() ) {
* 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() {
global $wgJobClasses;
$this->assertNotReadOnly();
- if ( !WikiMap::isCurrentWikiDomain( $this->domain ) ) {
- throw new MWException(
+ if ( !WikiMap::isCurrentWikiDbDomain( $this->domain ) ) {
+ 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();
- if ( !$job ) {
- $this->aggr->notifyQueueEmpty( $this->domain, $this->type );
- }
-
// Flag this job as an old duplicate based on its "root" job...
try {
if ( $job && $this->isRootJobOldDuplicate( $job ) ) {
*
* @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 ) {
$stats->updateCount( "jobqueue.{$key}.{$type}", $delta );
}
}
-
-/**
- * @ingroup JobQueue
- * @since 1.22
- */
-class JobQueueError extends MWException {
-}
-
-class JobQueueConnectionError extends JobQueueError {
-}
-
-class JobQueueReadOnlyError extends JobQueueError {
-
-}