MediaWiki  REL1_21
JobQueueAggregator.php
Go to the documentation of this file.
00001 <?php
00030 abstract class JobQueueAggregator {
00032         protected static $instance = null;
00033 
00037         protected function __construct( array $params ) {}
00038 
00042         final public static function singleton() {
00043                 global $wgJobQueueAggregator;
00044 
00045                 if ( !isset( self::$instance ) ) {
00046                         $class = $wgJobQueueAggregator['class'];
00047                         $obj = new $class( $wgJobQueueAggregator );
00048                         if ( !( $obj instanceof JobQueueAggregator ) ) {
00049                                 throw new MWException( "Class '$class' is not a JobQueueAggregator class." );
00050                         }
00051                         self::$instance = $obj;
00052                 }
00053 
00054                 return self::$instance;
00055         }
00056 
00062         final public static function destroySingleton() {
00063                 self::$instance = null;
00064         }
00065 
00073         final public function notifyQueueEmpty( $wiki, $type ) {
00074                 wfProfileIn( __METHOD__ );
00075                 $ok = $this->doNotifyQueueEmpty( $wiki, $type );
00076                 wfProfileOut( __METHOD__ );
00077                 return $ok;
00078         }
00079 
00083         abstract protected function doNotifyQueueEmpty( $wiki, $type );
00084 
00092         final public function notifyQueueNonEmpty( $wiki, $type ) {
00093                 wfProfileIn( __METHOD__ );
00094                 $ok = $this->doNotifyQueueNonEmpty( $wiki, $type );
00095                 wfProfileOut( __METHOD__ );
00096                 return $ok;
00097         }
00098 
00102         abstract protected function doNotifyQueueNonEmpty( $wiki, $type );
00103 
00109         final public function getAllReadyWikiQueues() {
00110                 wfProfileIn( __METHOD__ );
00111                 $res = $this->doGetAllReadyWikiQueues();
00112                 wfProfileOut( __METHOD__ );
00113                 return $res;
00114         }
00115 
00119         abstract protected function doGetAllReadyWikiQueues();
00120 
00127         protected function findPendingWikiQueues() {
00128                 global $wgLocalDatabases;
00129 
00130                 $pendingDBs = array(); // (job type => (db list))
00131                 foreach ( $wgLocalDatabases as $db ) {
00132                         foreach ( JobQueueGroup::singleton( $db )->getQueuesWithJobs() as $type ) {
00133                                 $pendingDBs[$type][] = $db;
00134                         }
00135                 }
00136 
00137                 return $pendingDBs;
00138         }
00139 }