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
21 * @author Aaron Schulz
25 * Class to handle tracking information about all queues
30 abstract class JobQueueAggregator
{
31 /** @var JobQueueAggregator */
32 protected static $instance = null;
35 * @param array $params
37 public function __construct( array $params ) {
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;
60 * Destroy the singleton instance
64 final public static function destroySingleton() {
65 self
::$instance = null;
69 * Mark a queue as being empty
73 * @return bool Success
75 final public function notifyQueueEmpty( $wiki, $type ) {
76 $ok = $this->doNotifyQueueEmpty( $wiki, $type );
82 * @see JobQueueAggregator::notifyQueueEmpty()
84 abstract protected function doNotifyQueueEmpty( $wiki, $type );
87 * Mark a queue as being non-empty
91 * @return bool Success
93 final public function notifyQueueNonEmpty( $wiki, $type ) {
94 $ok = $this->doNotifyQueueNonEmpty( $wiki, $type );
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();
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();
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;
156 class JobQueueAggregatorNull
extends JobQueueAggregator
{
157 protected function doNotifyQueueEmpty( $wiki, $type ) {
161 protected function doNotifyQueueNonEmpty( $wiki, $type ) {
165 protected function doGetAllReadyWikiQueues() {
169 protected function doPurge() {