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
24 * Class to handle tracking information about all queues
29 abstract class JobQueueAggregator
{
30 /** @var JobQueueAggregator */
31 protected static $instance = null;
34 * @param array $params
36 public function __construct( array $params ) {
41 * @return JobQueueAggregator
43 final public static function singleton() {
44 global $wgJobQueueAggregator;
46 if ( !isset( self
::$instance ) ) {
47 $class = $wgJobQueueAggregator['class'];
48 $obj = new $class( $wgJobQueueAggregator );
49 if ( !( $obj instanceof JobQueueAggregator
) ) {
50 throw new MWException( "Class '$class' is not a JobQueueAggregator class." );
52 self
::$instance = $obj;
55 return self
::$instance;
59 * Destroy the singleton instance
63 final public static function destroySingleton() {
64 self
::$instance = null;
68 * Mark a queue as being empty
72 * @return bool Success
74 final public function notifyQueueEmpty( $wiki, $type ) {
75 $ok = $this->doNotifyQueueEmpty( $wiki, $type );
81 * @see JobQueueAggregator::notifyQueueEmpty()
86 abstract protected function doNotifyQueueEmpty( $wiki, $type );
89 * Mark a queue as being non-empty
93 * @return bool Success
95 final public function notifyQueueNonEmpty( $wiki, $type ) {
96 $ok = $this->doNotifyQueueNonEmpty( $wiki, $type );
102 * @see JobQueueAggregator::notifyQueueNonEmpty()
103 * @param string $wiki
104 * @param string $type
107 abstract protected function doNotifyQueueNonEmpty( $wiki, $type );
110 * Get the list of all of the queues with jobs
112 * @return array (job type => (list of wiki IDs))
114 final public function getAllReadyWikiQueues() {
115 $res = $this->doGetAllReadyWikiQueues();
121 * @see JobQueueAggregator::getAllReadyWikiQueues()
123 abstract protected function doGetAllReadyWikiQueues();
126 * Purge all of the aggregator information
128 * @return bool Success
130 final public function purge() {
131 $res = $this->doPurge();
137 * @see JobQueueAggregator::purge()
139 abstract protected function doPurge();
142 * Get all databases that have a pending job.
143 * This poll all the queues and is this expensive.
145 * @return array (job type => (list of wiki IDs))
147 protected function findPendingWikiQueues() {
148 global $wgLocalDatabases;
150 $pendingDBs = []; // (job type => (db list))
151 foreach ( $wgLocalDatabases as $db ) {
152 foreach ( JobQueueGroup
::singleton( $db )->getQueuesWithJobs() as $type ) {
153 $pendingDBs[$type][] = $db;
161 class JobQueueAggregatorNull
extends JobQueueAggregator
{
162 protected function doNotifyQueueEmpty( $wiki, $type ) {
166 protected function doNotifyQueueNonEmpty( $wiki, $type ) {
170 protected function doGetAllReadyWikiQueues() {
174 protected function doPurge() {