Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / includes / jobqueue / aggregator / JobQueueAggregator.php
blob41699748eede5d6b98eb6a0a0fbee93e8734b79a
1 <?php
2 /**
3 * Job queue aggregator code.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @author Aaron Schulz
24 /**
25 * Class to handle tracking information about all queues
27 * @ingroup JobQueue
28 * @since 1.21
30 abstract class JobQueueAggregator {
31 /** @var JobQueueAggregator */
32 protected static $instance = null;
34 /**
35 * @param array $params
37 public function __construct( array $params ) {
40 /**
41 * @throws MWException
42 * @return JobQueueAggregator
44 final public static function singleton() {
45 global $wgJobQueueAggregator;
47 if ( !isset( self::$instance ) ) {
48 $class = $wgJobQueueAggregator['class'];
49 $obj = new $class( $wgJobQueueAggregator );
50 if ( !( $obj instanceof JobQueueAggregator ) ) {
51 throw new MWException( "Class '$class' is not a JobQueueAggregator class." );
53 self::$instance = $obj;
56 return self::$instance;
59 /**
60 * Destroy the singleton instance
62 * @return void
64 final public static function destroySingleton() {
65 self::$instance = null;
68 /**
69 * Mark a queue as being empty
71 * @param string $wiki
72 * @param string $type
73 * @return bool Success
75 final public function notifyQueueEmpty( $wiki, $type ) {
76 $ok = $this->doNotifyQueueEmpty( $wiki, $type );
78 return $ok;
81 /**
82 * @see JobQueueAggregator::notifyQueueEmpty()
84 abstract protected function doNotifyQueueEmpty( $wiki, $type );
86 /**
87 * Mark a queue as being non-empty
89 * @param string $wiki
90 * @param string $type
91 * @return bool Success
93 final public function notifyQueueNonEmpty( $wiki, $type ) {
94 $ok = $this->doNotifyQueueNonEmpty( $wiki, $type );
96 return $ok;
99 /**
100 * @see JobQueueAggregator::notifyQueueNonEmpty()
102 abstract protected function doNotifyQueueNonEmpty( $wiki, $type );
105 * Get the list of all of the queues with jobs
107 * @return array (job type => (list of wiki IDs))
109 final public function getAllReadyWikiQueues() {
110 $res = $this->doGetAllReadyWikiQueues();
112 return $res;
116 * @see JobQueueAggregator::getAllReadyWikiQueues()
118 abstract protected function doGetAllReadyWikiQueues();
121 * Purge all of the aggregator information
123 * @return bool Success
125 final public function purge() {
126 $res = $this->doPurge();
128 return $res;
132 * @see JobQueueAggregator::purge()
134 abstract protected function doPurge();
137 * Get all databases that have a pending job.
138 * This poll all the queues and is this expensive.
140 * @return array (job type => (list of wiki IDs))
142 protected function findPendingWikiQueues() {
143 global $wgLocalDatabases;
145 $pendingDBs = []; // (job type => (db list))
146 foreach ( $wgLocalDatabases as $db ) {
147 foreach ( JobQueueGroup::singleton( $db )->getQueuesWithJobs() as $type ) {
148 $pendingDBs[$type][] = $db;
152 return $pendingDBs;
156 class JobQueueAggregatorNull extends JobQueueAggregator {
157 protected function doNotifyQueueEmpty( $wiki, $type ) {
158 return true;
161 protected function doNotifyQueueNonEmpty( $wiki, $type ) {
162 return true;
165 protected function doGetAllReadyWikiQueues() {
166 return [];
169 protected function doPurge() {
170 return true;