48 private $jobQueueGroup;
56 $job =
new self( $handle->
getTitle(), [
'command' => $command ] );
70 'command' =>
'rebuild',
76 $this->jobQueueGroup = MediaWikiServices::getInstance()->getJobQueueGroup();
83 public function run() {
84 global $wgTranslateTranslationServices,
85 $wgTranslateTranslationDefaultService;
87 $service = $this->params[
'service'];
88 $writeToMirrors =
false;
90 if ( $service ===
null ) {
91 $service = $wgTranslateTranslationDefaultService;
92 $writeToMirrors =
true;
95 if ( !isset( $wgTranslateTranslationServices[$service] ) ) {
96 LoggerFactory::getInstance(
'TTMServerUpdates' )->warning(
97 'Received update job for a an unknown service {service}.',
98 [
'service' => $service ]
103 $services = [ $service ];
104 if ( $writeToMirrors ) {
105 $config = $wgTranslateTranslationServices[$service];
106 $server = TTMServer::factory( $config );
107 $services = array_unique(
108 array_merge( $services, $server->getMirrors() )
112 foreach ( $services as $service ) {
113 $this->runCommandWithRetry( $service );
128 private function runCommandWithRetry( $serviceName ) {
129 global $wgTranslateTranslationServices;
131 if ( !isset( $wgTranslateTranslationServices[$serviceName] ) ) {
132 LoggerFactory::getInstance(
'TTMServerUpdates' )->warning(
133 'Cannot write to {service}: service is unknown.',
134 [
'service' => $serviceName ]
141 LoggerFactory::getInstance(
'TTMServerUpdates' )->warning(
142 'Received update job for a service that does not implement ' .
143 'WritableTTMServer, please check config for {service}.',
144 [
'service' => $serviceName ]
150 $this->runCommand( $ttmserver );
151 }
catch ( Exception $e ) {
152 $this->requeueError( $serviceName, $e );
160 private function requeueError( $serviceName, $e ) {
161 LoggerFactory::getInstance(
'TTMServerUpdates' )->warning(
162 'Exception thrown while running {command} on ' .
163 'service {service}: {errorMessage}',
165 'command' => $this->params[
'command'],
166 'service' => $serviceName,
167 'errorMessage' => $e->getMessage(),
171 if ( $this->params[
'errorCount'] >= self::MAX_ERROR_RETRY ) {
172 LoggerFactory::getInstance(
'TTMServerUpdates' )->warning(
173 'Dropping failing job {command} for service {service} ' .
174 'after repeated failure',
176 'command' => $this->params[
'command'],
177 'service' => $serviceName,
185 $job->params[
'errorCount']++;
186 $job->params[
'service'] = $serviceName;
187 $job->setDelay( $delay );
188 LoggerFactory::getInstance(
'TTMServerUpdates' )->info(
189 'Update job reported failure on service {service}. ' .
190 'Requeueing job with delay of {delay}.',
192 'service' => $serviceName,
204 $this->jobQueueGroup->push( $job );
209 $command = $this->params[
'command'];
211 if ( $command ===
'delete' ) {
212 $this->updateItem( $ttmserver, $handle,
null,
false );
213 } elseif ( $command ===
'rebuild' ) {
214 $this->updateMessage( $ttmserver, $handle );
215 } elseif ( $command ===
'refresh' ) {
216 $this->updateTranslation( $ttmserver, $handle );
236 return Utilities::getMessageContent(
245 $translations = Utilities::getTranslations( $handle );
246 foreach ( $translations as $page => $data ) {
247 $tTitle = Title::makeTitle( $this->title->getNamespace(), $page );
249 $this->updateItem( $ttmserver, $tHandle, $data[0], $tHandle->isFuzzy() );
256 $this->updateItem( $ttmserver, $handle, $translation, $handle->
isFuzzy() );
263 $ttmserver->
update( $handle, $text );
278 $jobQueue = $this->jobQueueGroup->get( $this->getType() );
279 if ( !$delay || !$jobQueue->delayedJobsEnabled() ) {
282 $oldTime = $this->getReleaseTimestamp();
283 $newTime = time() + $delay;
284 if ( $oldTime !==
null && $oldTime >= $newTime ) {
287 $this->params[
'jobReleaseTimestamp' ] = $newTime;
299 static::WRITE_BACKOFF_EXPONENT + rand( 0, min( $errorCount, 4 ) )