Merge "HTMLFormFieldWithButton: Allow passing 'inputtype' and pass through 'buttonid'"
[lhc/web/wiklou.git] / includes / jobqueue / JobQueueGroup.php
index 4853c4a..83e5fb2 100644 (file)
@@ -71,16 +71,16 @@ class JobQueueGroup {
                global $wgLocalDatabases;
 
                if ( $domain === false ) {
-                       $domain = WikiMap::getCurrentWikiDomain()->getId();
+                       $domain = WikiMap::getCurrentWikiDbDomain()->getId();
                }
 
                if ( !isset( self::$instances[$domain] ) ) {
                        self::$instances[$domain] = new self( $domain, wfConfiguredReadOnlyReason() );
                        // Make sure jobs are not getting pushed to bogus wikis. This can confuse
                        // the job runner system into spawning endless RPC requests that fail (T171371).
-                       $wikiId = WikiMap::getWikiIdFromDomain( $domain );
+                       $wikiId = WikiMap::getWikiIdFromDbDomain( $domain );
                        if (
-                               !WikiMap::isCurrentWikiDomain( $domain ) &&
+                               !WikiMap::isCurrentWikiDbDomain( $domain ) &&
                                !in_array( $wikiId, $wgLocalDatabases )
                        ) {
                                self::$instances[$domain]->invalidDomain = true;
@@ -114,11 +114,15 @@ class JobQueueGroup {
                } else {
                        $conf = $conf + $wgJobTypeConf['default'];
                }
-               $conf['aggregator'] = JobQueueAggregator::singleton();
                if ( !isset( $conf['readOnlyReason'] ) ) {
                        $conf['readOnlyReason'] = $this->readOnlyReason;
                }
 
+               $services = MediaWikiServices::getInstance();
+               $conf['stats'] = $services->getStatsdDataFactory();
+               $conf['wanCache'] = $services->getMainWANObjectCache();
+               $conf['stash'] = $services->getMainObjectStash();
+
                return JobQueue::factory( $conf );
        }
 
@@ -230,11 +234,21 @@ class JobQueueGroup {
         * @param int|string $qtype JobQueueGroup::TYPE_* constant or job type string
         * @param int $flags Bitfield of JobQueueGroup::USE_* constants
         * @param array $blacklist List of job types to ignore
-        * @return Job|bool Returns false on failure
+        * @return RunnableJob|bool Returns false on failure
         */
        public function pop( $qtype = self::TYPE_DEFAULT, $flags = 0, array $blacklist = [] ) {
+               global $wgJobClasses;
+
                $job = false;
 
+               if ( !WikiMap::isCurrentWikiDbDomain( $this->domain ) ) {
+                       throw new JobQueueError(
+                               "Cannot pop '{$qtype}' job off foreign '{$this->domain}' wiki queue." );
+               } elseif ( is_string( $qtype ) && !isset( $wgJobClasses[$qtype] ) ) {
+                       // Do not pop jobs if there is no class for the queue type
+                       throw new JobQueueError( "Unrecognized job type '$qtype'." );
+               }
+
                if ( is_string( $qtype ) ) { // specific job type
                        if ( !in_array( $qtype, $blacklist ) ) {
                                $job = $this->get( $qtype )->pop();
@@ -353,12 +367,14 @@ class JobQueueGroup {
        /**
         * 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
@@ -376,12 +392,14 @@ class JobQueueGroup {
        /**
         * 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
@@ -395,7 +413,7 @@ class JobQueueGroup {
        }
 
        /**
-        * @return array
+        * @return JobQueue[]
         */
        protected function getCoalescedQueues() {
                global $wgJobTypeConf;
@@ -404,7 +422,7 @@ class JobQueueGroup {
                        $this->coalescedQueues = [];
                        foreach ( $wgJobTypeConf as $type => $conf ) {
                                $queue = JobQueue::factory(
-                                       [ 'wiki' => $this->domain, 'type' => 'null' ] + $conf );
+                                       [ 'domain' => $this->domain, 'type' => 'null' ] + $conf );
                                $loc = $queue->getCoalesceLocationInternal();
                                if ( !isset( $this->coalescedQueues[$loc] ) ) {
                                        $this->coalescedQueues[$loc]['queue'] = $queue;
@@ -430,10 +448,10 @@ class JobQueueGroup {
         */
        private function getCachedConfigVar( $name ) {
                // @TODO: cleanup this whole method with a proper config system
-               if ( WikiMap::isCurrentWikiDomain( $this->domain ) ) {
+               if ( WikiMap::isCurrentWikiDbDomain( $this->domain ) ) {
                        return $GLOBALS[$name]; // common case
                } else {
-                       $wiki = WikiMap::getWikiIdFromDomain( $this->domain );
+                       $wiki = WikiMap::getWikiIdFromDbDomain( $this->domain );
                        $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                        $value = $cache->getWithSetCallback(
                                $cache->makeGlobalKey( 'jobqueue', 'configvalue', $this->domain, $name ),