X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fjobqueue%2FJobQueue.php;h=064400268e524724794438a7882393fb636b8228;hp=c9f17cf54ce64355639b2b1867d66dd35936688e;hb=a38af7ba26579bb3004f673e44d39710887763aa;hpb=1e7da67c180092b1c2effc77f590cc160127ce72 diff --git a/includes/jobqueue/JobQueue.php b/includes/jobqueue/JobQueue.php index c9f17cf54c..064400268e 100644 --- a/includes/jobqueue/JobQueue.php +++ b/includes/jobqueue/JobQueue.php @@ -20,7 +20,7 @@ * @file * @defgroup JobQueue JobQueue */ -use MediaWiki\MediaWikiServices; +use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface; /** * Class to handle enqueueing and running of background jobs @@ -41,11 +41,11 @@ abstract class JobQueue { protected $maxTries; /** @var string|bool Read only rationale (or false if r/w) */ protected $readOnlyReason; + /** @var StatsdDataFactoryInterface */ + protected $stats; /** @var BagOStuff */ protected $dupCache; - /** @var JobQueueAggregator */ - protected $aggr; const QOS_ATOMIC = 1; // integer; "all-or-nothing" job insertions @@ -68,9 +68,9 @@ abstract class JobQueue { if ( !in_array( $this->order, $this->supportedOrders() ) ) { 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; + $this->stats = $params['stats'] ?? new NullStatsdDataFactory(); + $this->dupCache = $params['stash'] ?? new EmptyBagOStuff(); } /** @@ -94,6 +94,8 @@ abstract class JobQueue { * 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. + * - stash : A BagOStuff instance that can be used for root job deduplication + * - stats : A StatsdDataFactoryInterface [optional] * * Queue classes should throw an exception if they do not support the options given. * @@ -115,7 +117,7 @@ abstract class JobQueue { } /** - * @return string Wiki ID + * @return string Database domain ID */ final public function getDomain() { return $this->domain; @@ -338,7 +340,6 @@ abstract class JobQueue { } $this->doBatchPush( $jobs, $flags ); - $this->aggr->notifyQueueNonEmpty( $this->domain, $this->type ); foreach ( $jobs as $job ) { if ( $job->isRootJob() ) { @@ -363,27 +364,14 @@ abstract class JobQueue { * @return Job|bool Returns false if there are no jobs */ final public function pop() { - global $wgJobClasses; - $this->assertNotReadOnly(); - 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 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 ) ) { - self::incrStats( 'dupe_pops', $this->type ); + $this->incrStats( 'dupe_pops', $this->type ); $job = DuplicateJob::newFromJob( $job ); // convert to a no-op } } catch ( Exception $e ) { @@ -488,7 +476,7 @@ abstract class JobQueue { } // Update the timestamp of the last root job started at the location... - return $this->dupCache->set( $key, $params['rootJobTimestamp'], JobQueueDB::ROOTJOB_TTL ); + return $this->dupCache->set( $key, $params['rootJobTimestamp'], self::ROOTJOB_TTL ); } /** @@ -715,12 +703,8 @@ abstract class JobQueue { * @param int $delta * @since 1.22 */ - public static function incrStats( $key, $type, $delta = 1 ) { - static $stats; - if ( !$stats ) { - $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); - } - $stats->updateCount( "jobqueue.{$key}.all", $delta ); - $stats->updateCount( "jobqueue.{$key}.{$type}", $delta ); + protected function incrStats( $key, $type, $delta = 1 ) { + $this->stats->updateCount( "jobqueue.{$key}.all", $delta ); + $this->stats->updateCount( "jobqueue.{$key}.{$type}", $delta ); } }