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()
83 abstract protected function doNotifyQueueEmpty( $wiki, $type );
86 * Mark a queue as being non-empty
90 * @return bool Success
92 final public function notifyQueueNonEmpty( $wiki, $type ) {
93 $ok = $this->doNotifyQueueNonEmpty( $wiki, $type );
99 * @see JobQueueAggregator::notifyQueueNonEmpty()
101 abstract protected function doNotifyQueueNonEmpty( $wiki, $type );
104 * Get the list of all of the queues with jobs
106 * @return array (job type => (list of wiki IDs))
108 final public function getAllReadyWikiQueues() {
109 $res = $this->doGetAllReadyWikiQueues();
115 * @see JobQueueAggregator::getAllReadyWikiQueues()
117 abstract protected function doGetAllReadyWikiQueues();
120 * Purge all of the aggregator information
122 * @return bool Success
124 final public function purge() {
125 $res = $this->doPurge();
131 * @see JobQueueAggregator::purge()
133 abstract protected function doPurge();
136 * Get all databases that have a pending job.
137 * This poll all the queues and is this expensive.
139 * @return array (job type => (list of wiki IDs))
141 protected function findPendingWikiQueues() {
142 global $wgLocalDatabases;
144 $pendingDBs = []; // (job type => (db list))
145 foreach ( $wgLocalDatabases as $db ) {
146 foreach ( JobQueueGroup
::singleton( $db )->getQueuesWithJobs() as $type ) {
147 $pendingDBs[$type][] = $db;
155 class JobQueueAggregatorNull
extends JobQueueAggregator
{
156 protected function doNotifyQueueEmpty( $wiki, $type ) {
160 protected function doNotifyQueueNonEmpty( $wiki, $type ) {
164 protected function doGetAllReadyWikiQueues() {
168 protected function doPurge() {