X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fjobqueue%2FJobQueue.php;h=d64be3c409cdb6eb0352a9215b1ca8be2d658267;hb=94818adfb7af9e929b23a0d40b7fd8143727b2c7;hp=89948f46bafbd4945522f6093930f750f4907daf;hpb=ea9fcc1e4d3b572199d82c426024e3e5efe23879;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/jobqueue/JobQueue.php b/includes/jobqueue/JobQueue.php index 89948f46ba..d64be3c409 100644 --- a/includes/jobqueue/JobQueue.php +++ b/includes/jobqueue/JobQueue.php @@ -31,18 +31,16 @@ abstract class JobQueue { /** @var string Wiki ID */ protected $wiki; - /** @var string Job type */ protected $type; - /** @var string Job priority for pop() */ protected $order; - /** @var int Time to live in seconds */ protected $claimTTL; - /** @var int Maximum number of times to try a job */ protected $maxTries; + /** @var string|bool Read only rationale (or false if r/w) */ + protected $readOnlyReason; /** @var BagOStuff */ protected $dupCache; @@ -73,7 +71,10 @@ abstract class JobQueue { $this->dupCache = wfGetCache( CACHE_ANYTHING ); $this->aggr = isset( $params['aggregator'] ) ? $params['aggregator'] - : new JobQueueAggregatorNull( array() ); + : new JobQueueAggregatorNull( [] ); + $this->readOnlyReason = isset( $params['readOnlyReason'] ) + ? $params['readOnlyReason'] + : false; } /** @@ -96,6 +97,7 @@ abstract class JobQueue { * but not acknowledged as completed after this many seconds. Recycling * of jobs simply means re-inserting them into the queue. Jobs can be * attempted up to three times before being discarded. + * - readOnlyReason : Set this to a string to make the queue read-only. * * Queue classes should throw an exception if they do not support the options given. * @@ -168,6 +170,14 @@ abstract class JobQueue { return $this->supportsDelayedJobs(); } + /** + * @return string|bool Read-only rational or false if r/w + * @since 1.27 + */ + public function getReadOnlyReason() { + return $this->readOnlyReason; + } + /** * Quickly check if the queue has no available (unacquired, non-delayed) jobs. * Queue classes should use caching if they are any slower without memcached. @@ -286,13 +296,13 @@ abstract class JobQueue { * This does not require $wgJobClasses to be set for the given job type. * Outside callers should use JobQueueGroup::push() instead of this function. * - * @param JobSpecification|JobSpecification[] $jobs + * @param IJobSpecification|IJobSpecification[] $jobs * @param int $flags Bitfield (supports JobQueue::QOS_ATOMIC) * @return void * @throws JobQueueError */ final public function push( $jobs, $flags = 0 ) { - $jobs = is_array( $jobs ) ? $jobs : array( $jobs ); + $jobs = is_array( $jobs ) ? $jobs : [ $jobs ]; $this->batchPush( $jobs, $flags ); } @@ -301,12 +311,14 @@ abstract class JobQueue { * This does not require $wgJobClasses to be set for the given job type. * Outside callers should use JobQueueGroup::push() instead of this function. * - * @param JobSpecification[] $jobs + * @param IJobSpecification[] $jobs * @param int $flags Bitfield (supports JobQueue::QOS_ATOMIC) * @return void * @throws MWException */ final public function batchPush( array $jobs, $flags = 0 ) { + $this->assertNotReadOnly(); + if ( !count( $jobs ) ) { return; // nothing to do } @@ -333,7 +345,7 @@ abstract class JobQueue { /** * @see JobQueue::batchPush() - * @param JobSpecification[] $jobs + * @param IJobSpecification[] $jobs * @param int $flags */ abstract protected function doBatchPush( array $jobs, $flags ); @@ -349,6 +361,7 @@ abstract class JobQueue { final public function pop() { global $wgJobClasses; + $this->assertNotReadOnly(); if ( $this->wiki !== wfWikiID() ) { throw new MWException( "Cannot pop '{$this->type}' job off foreign wiki queue." ); } elseif ( !isset( $wgJobClasses[$this->type] ) ) { @@ -377,7 +390,7 @@ abstract class JobQueue { /** * @see JobQueue::pop() - * @return Job + * @return Job|bool */ abstract protected function doPop(); @@ -392,9 +405,11 @@ abstract class JobQueue { * @throws MWException */ final public function ack( Job $job ) { + $this->assertNotReadOnly(); if ( $job->getType() !== $this->type ) { throw new MWException( "Got '{$job->getType()}' job; expected '{$this->type}'." ); } + $this->doAck( $job ); } @@ -436,12 +451,12 @@ abstract class JobQueue { * @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}'." ); } - $ok = $this->doDeduplicateRootJob( $job ); - return $ok; + return $this->doDeduplicateRootJob( $job ); } /** @@ -524,6 +539,8 @@ abstract class JobQueue { * @return void */ final public function delete() { + $this->assertNotReadOnly(); + $this->doDelete(); } @@ -589,7 +606,7 @@ abstract class JobQueue { * @since 1.22 */ public function getAllDelayedJobs() { - return new ArrayIterator( array() ); // not implemented + return new ArrayIterator( [] ); // not implemented } /** @@ -603,7 +620,7 @@ abstract class JobQueue { * @since 1.26 */ public function getAllAcquiredJobs() { - return new ArrayIterator( array() ); // not implemented + return new ArrayIterator( [] ); // not implemented } /** @@ -614,7 +631,7 @@ abstract class JobQueue { * @since 1.25 */ public function getAllAbandonedJobs() { - return new ArrayIterator( array() ); // not implemented + return new ArrayIterator( [] ); // not implemented } /** @@ -672,6 +689,15 @@ abstract class JobQueue { return null; // not supported } + /** + * @throws JobQueueReadOnlyError + */ + protected function assertNotReadOnly() { + if ( $this->readOnlyReason !== false ) { + throw new JobQueueReadOnlyError( "Job queue is read-only: {$this->readOnlyReason}" ); + } + } + /** * Call wfIncrStats() for the queue overall and for the queue type * @@ -699,3 +725,7 @@ class JobQueueError extends MWException { class JobQueueConnectionError extends JobQueueError { } + +class JobQueueReadOnlyError extends JobQueueError { + +}