MediaWiki  REL1_22
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 
00126     final public function purge() {
00127         wfProfileIn( __METHOD__ );
00128         $res = $this->doPurge();
00129         wfProfileOut( __METHOD__ );
00130         return $res;
00131     }
00132 
00136     abstract protected function doPurge();
00137 
00144     protected function findPendingWikiQueues() {
00145         global $wgLocalDatabases;
00146 
00147         $pendingDBs = array(); // (job type => (db list))
00148         foreach ( $wgLocalDatabases as $db ) {
00149             foreach ( JobQueueGroup::singleton( $db )->getQueuesWithJobs() as $type ) {
00150                 $pendingDBs[$type][] = $db;
00151             }
00152         }
00153 
00154         return $pendingDBs;
00155     }
00156 }