[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Job queue aggregator code. 4 * 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. 9 * 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. 14 * 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 19 * 20 * @file 21 * @author Aaron Schulz 22 */ 23 24 /** 25 * Class to handle tracking information about all queues 26 * 27 * @ingroup JobQueue 28 * @since 1.21 29 */ 30 abstract class JobQueueAggregator { 31 /** @var JobQueueAggregator */ 32 protected static $instance = null; 33 34 /** 35 * @param array $params 36 */ 37 protected function __construct( array $params ) { 38 } 39 40 /** 41 * @throws MWException 42 * @return JobQueueAggregator 43 */ 44 final public static function singleton() { 45 global $wgJobQueueAggregator; 46 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." ); 52 } 53 self::$instance = $obj; 54 } 55 56 return self::$instance; 57 } 58 59 /** 60 * Destroy the singleton instance 61 * 62 * @return void 63 */ 64 final public static function destroySingleton() { 65 self::$instance = null; 66 } 67 68 /** 69 * Mark a queue as being empty 70 * 71 * @param string $wiki 72 * @param string $type 73 * @return bool Success 74 */ 75 final public function notifyQueueEmpty( $wiki, $type ) { 76 wfProfileIn( __METHOD__ ); 77 $ok = $this->doNotifyQueueEmpty( $wiki, $type ); 78 wfProfileOut( __METHOD__ ); 79 80 return $ok; 81 } 82 83 /** 84 * @see JobQueueAggregator::notifyQueueEmpty() 85 */ 86 abstract protected function doNotifyQueueEmpty( $wiki, $type ); 87 88 /** 89 * Mark a queue as being non-empty 90 * 91 * @param string $wiki 92 * @param string $type 93 * @return bool Success 94 */ 95 final public function notifyQueueNonEmpty( $wiki, $type ) { 96 wfProfileIn( __METHOD__ ); 97 $ok = $this->doNotifyQueueNonEmpty( $wiki, $type ); 98 wfProfileOut( __METHOD__ ); 99 100 return $ok; 101 } 102 103 /** 104 * @see JobQueueAggregator::notifyQueueNonEmpty() 105 */ 106 abstract protected function doNotifyQueueNonEmpty( $wiki, $type ); 107 108 /** 109 * Get the list of all of the queues with jobs 110 * 111 * @return array (job type => (list of wiki IDs)) 112 */ 113 final public function getAllReadyWikiQueues() { 114 wfProfileIn( __METHOD__ ); 115 $res = $this->doGetAllReadyWikiQueues(); 116 wfProfileOut( __METHOD__ ); 117 118 return $res; 119 } 120 121 /** 122 * @see JobQueueAggregator::getAllReadyWikiQueues() 123 */ 124 abstract protected function doGetAllReadyWikiQueues(); 125 126 /** 127 * Purge all of the aggregator information 128 * 129 * @return bool Success 130 */ 131 final public function purge() { 132 wfProfileIn( __METHOD__ ); 133 $res = $this->doPurge(); 134 wfProfileOut( __METHOD__ ); 135 136 return $res; 137 } 138 139 /** 140 * @see JobQueueAggregator::purge() 141 */ 142 abstract protected function doPurge(); 143 144 /** 145 * Get all databases that have a pending job. 146 * This poll all the queues and is this expensive. 147 * 148 * @return array (job type => (list of wiki IDs)) 149 */ 150 protected function findPendingWikiQueues() { 151 global $wgLocalDatabases; 152 153 $pendingDBs = array(); // (job type => (db list)) 154 foreach ( $wgLocalDatabases as $db ) { 155 foreach ( JobQueueGroup::singleton( $db )->getQueuesWithJobs() as $type ) { 156 $pendingDBs[$type][] = $db; 157 } 158 } 159 160 return $pendingDBs; 161 } 162 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |