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 protected function __construct( array $params ) {}
40 * @return JobQueueAggregator
42 final public static function singleton() {
43 global $wgJobQueueAggregator;
45 if ( !isset( self
::$instance ) ) {
46 $class = $wgJobQueueAggregator['class'];
47 $obj = new $class( $wgJobQueueAggregator );
48 if ( !( $obj instanceof JobQueueAggregator
) ) {
49 throw new MWException( "Class '$class' is not a JobQueueAggregator class." );
51 self
::$instance = $obj;
54 return self
::$instance;
58 * Destroy the singleton instance
62 final public static function destroySingleton() {
63 self
::$instance = null;
67 * Mark a queue as being empty
71 * @return bool Success
73 final public function notifyQueueEmpty( $wiki, $type ) {
74 wfProfileIn( __METHOD__
);
75 $ok = $this->doNotifyQueueEmpty( $wiki, $type );
76 wfProfileOut( __METHOD__
);
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 wfProfileIn( __METHOD__
);
94 $ok = $this->doNotifyQueueNonEmpty( $wiki, $type );
95 wfProfileOut( __METHOD__
);
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 wfProfileIn( __METHOD__
);
111 $res = $this->doGetAllReadyWikiQueues();
112 wfProfileOut( __METHOD__
);
117 * @see JobQueueAggregator::getAllReadyWikiQueues()
119 abstract protected function doGetAllReadyWikiQueues();
122 * Purge all of the aggregator information
124 * @return bool Success
126 final public function purge() {
127 wfProfileIn( __METHOD__
);
128 $res = $this->doPurge();
129 wfProfileOut( __METHOD__
);
134 * @see JobQueueAggregator::purge()
136 abstract protected function doPurge();
139 * Get all databases that have a pending job.
140 * This poll all the queues and is this expensive.
142 * @return Array (job type => (list of wiki IDs))
144 protected function findPendingWikiQueues() {
145 global $wgLocalDatabases;
147 $pendingDBs = array(); // (job type => (db list))
148 foreach ( $wgLocalDatabases as $db ) {
149 foreach ( JobQueueGroup
::singleton( $db )->getQueuesWithJobs() as $type ) {
150 $pendingDBs[$type][] = $db;