/** * Initializes members from command line options and configuration settings. * * @param ChangeLookup $changeLookup * @param SettingsArray $settings * * @return ChangeDispatcher * @throws MWException */ private function newChangeDispatcher(ChangeLookup $changeLookup, SettingsArray $settings) { $repoDB = $settings->getSetting('changesDatabase'); $clientWikis = $settings->getSetting('localClientDatabases'); $batchChunkFactor = $settings->getSetting('dispatchBatchChunkFactor'); $batchCacheFactor = $settings->getSetting('dispatchBatchCacheFactor'); $subscriptionLookupMode = $settings->getSetting('subscriptionLookupMode'); $batchSize = (int) $this->getOption('batch-size', 1000); $maxChunks = (int) $this->getOption('max-chunks', 15); $dispatchInterval = (int) $this->getOption('dispatch-interval', 60); $lockGraceInterval = (int) $this->getOption('lock-grace-interval', 60); $randomness = (int) $this->getOption('randomness', 10); $this->verbose = $this->getOption('verbose', false); $cacheChunkSize = $batchSize * $batchChunkFactor; $cacheSize = $cacheChunkSize * $batchCacheFactor; $changesCache = new ChunkCache($changeLookup, $cacheChunkSize, $cacheSize); // make sure we have a mapping from siteId to database name in clientWikis: foreach ($clientWikis as $siteID => $dbName) { if (is_int($siteID)) { unset($clientWikis[$siteID]); $clientWikis[$dbName] = $dbName; } } if (empty($clientWikis)) { throw new MWException("No client wikis configured! Please set \$wgWBRepoSettings['localClientDatabases']."); } $reporter = new ObservableMessageReporter(); $self = $this; // PHP 5.3... $reporter->registerReporterCallback(function ($message) use($self) { $self->log($message); }); $coordinator = new SqlChangeDispatchCoordinator($repoDB, $clientWikis); $coordinator->setMessageReporter($reporter); $coordinator->setBatchSize($batchSize); $coordinator->setDispatchInterval($dispatchInterval); $coordinator->setLockGraceInterval($lockGraceInterval); $coordinator->setRandomness($randomness); $notificationSender = new JobQueueChangeNotificationSender($repoDB, $clientWikis); $subscriptionLookup = $this->getSubscriptionLookup($repoDB, $subscriptionLookupMode); $dispatcher = new ChangeDispatcher($coordinator, $notificationSender, $changesCache, $subscriptionLookup); $dispatcher->setMessageReporter($reporter); $dispatcher->setExceptionHandler(new ReportingExceptionHandler($reporter)); $dispatcher->setBatchSize($batchSize); $dispatcher->setMaxChunks($maxChunks); $dispatcher->setBatchChunkFactor($batchChunkFactor); $dispatcher->setVerbose($this->verbose); return $dispatcher; }
/** * Initializes members from command line options and configuration settings. * * @param string[] $clientWikis A mapping of client wiki site IDs to logical database names. * @param ChangeLookup $changeLookup * @param SettingsArray $settings * * @return ChangeDispatcher */ private function newChangeDispatcher(array $clientWikis, ChangeLookup $changeLookup, SettingsArray $settings) { $repoID = wfWikiID(); $repoDB = $settings->getSetting('changesDatabase'); $batchChunkFactor = $settings->getSetting('dispatchBatchChunkFactor'); $batchCacheFactor = $settings->getSetting('dispatchBatchCacheFactor'); $batchSize = (int) $this->getOption('batch-size', 1000); $maxChunks = (int) $this->getOption('max-chunks', 15); $dispatchInterval = (int) $this->getOption('dispatch-interval', 60); $lockGraceInterval = (int) $this->getOption('lock-grace-interval', 60); $randomness = (int) $this->getOption('randomness', 10); $this->verbose = $this->getOption('verbose', false); $cacheChunkSize = $batchSize * $batchChunkFactor; $cacheSize = $cacheChunkSize * $batchCacheFactor; $changesCache = new ChunkCache($changeLookup, $cacheChunkSize, $cacheSize); $reporter = new ObservableMessageReporter(); $self = $this; // PHP 5.3... $reporter->registerReporterCallback(function ($message) use($self) { $self->log($message); }); $coordinator = new SqlChangeDispatchCoordinator($repoDB, $repoID); $coordinator->setMessageReporter($reporter); $coordinator->setBatchSize($batchSize); $coordinator->setDispatchInterval($dispatchInterval); $coordinator->setLockGraceInterval($lockGraceInterval); $coordinator->setRandomness($randomness); $notificationSender = new JobQueueChangeNotificationSender($repoDB, $clientWikis); $subscriptionLookup = new SqlSubscriptionLookup(wfGetLB()); $dispatcher = new ChangeDispatcher($coordinator, $notificationSender, $changesCache, $subscriptionLookup); $dispatcher->setMessageReporter($reporter); $dispatcher->setExceptionHandler(new ReportingExceptionHandler($reporter)); $dispatcher->setBatchSize($batchSize); $dispatcher->setMaxChunks($maxChunks); $dispatcher->setBatchChunkFactor($batchChunkFactor); $dispatcher->setVerbose($this->verbose); return $dispatcher; }