47 private $jobQueueGroup;
55 $job =
new self( $handle->
getTitle(), [
'command' => $command ] );
69 'command' =>
'rebuild',
75 $this->jobQueueGroup = MediaWikiServices::getInstance()->getJobQueueGroup();
82 public function run() {
83 global $wgTranslateTranslationServices,
84 $wgTranslateTranslationDefaultService;
86 $service = $this->params[
'service'];
87 $writeToMirrors =
false;
89 if ( $service ===
null ) {
90 $service = $wgTranslateTranslationDefaultService;
91 $writeToMirrors =
true;
94 if ( !isset( $wgTranslateTranslationServices[$service] ) ) {
95 LoggerFactory::getInstance(
'TTMServerUpdates' )->warning(
96 'Received update job for a an unknown service {service}.',
97 [
'service' => $service ]
102 $services = [ $service ];
103 if ( $writeToMirrors ) {
104 $config = $wgTranslateTranslationServices[$service];
105 $server = TTMServer::factory( $config );
106 $services = array_unique(
107 array_merge( $services, $server->getMirrors() )
111 foreach ( $services as $service ) {
112 $this->runCommandWithRetry( $service );
127 private function runCommandWithRetry( $serviceName ) {
128 global $wgTranslateTranslationServices;
130 if ( !isset( $wgTranslateTranslationServices[$serviceName] ) ) {
131 LoggerFactory::getInstance(
'TTMServerUpdates' )->warning(
132 'Cannot write to {service}: service is unknown.',
133 [
'service' => $serviceName ]
140 LoggerFactory::getInstance(
'TTMServerUpdates' )->warning(
141 'Received update job for a service that does not implement ' .
142 'WritableTTMServer, please check config for {service}.',
143 [
'service' => $serviceName ]
149 $this->runCommand( $ttmserver );
150 }
catch ( Exception $e ) {
151 $this->requeueError( $serviceName, $e );
159 private function requeueError( $serviceName, $e ) {
160 LoggerFactory::getInstance(
'TTMServerUpdates' )->warning(
161 'Exception thrown while running {command} on ' .
162 'service {service}: {errorMessage}',
164 'command' => $this->params[
'command'],
165 'service' => $serviceName,
166 'errorMessage' => $e->getMessage(),
170 if ( $this->params[
'errorCount'] >= self::MAX_ERROR_RETRY ) {
171 LoggerFactory::getInstance(
'TTMServerUpdates' )->warning(
172 'Dropping failing job {command} for service {service} ' .
173 'after repeated failure',
175 'command' => $this->params[
'command'],
176 'service' => $serviceName,
184 $job->params[
'errorCount']++;
185 $job->params[
'service'] = $serviceName;
186 $job->setDelay( $delay );
187 LoggerFactory::getInstance(
'TTMServerUpdates' )->info(
188 'Update job reported failure on service {service}. ' .
189 'Requeueing job with delay of {delay}.',
191 'service' => $serviceName,
203 $this->jobQueueGroup->push( $job );
208 $command = $this->params[
'command'];
210 if ( $command ===
'delete' ) {
211 $this->updateItem( $ttmserver, $handle,
null,
false );
212 } elseif ( $command ===
'rebuild' ) {
213 $this->updateMessage( $ttmserver, $handle );
214 } elseif ( $command ===
'refresh' ) {
215 $this->updateTranslation( $ttmserver, $handle );
235 return TranslateUtils::getMessageContent(
244 $translations = TranslateUtils::getTranslations( $handle );
245 foreach ( $translations as $page => $data ) {
246 $tTitle = Title::makeTitle( $this->title->getNamespace(), $page );
248 $this->updateItem( $ttmserver, $tHandle, $data[0], $tHandle->isFuzzy() );
255 $this->updateItem( $ttmserver, $handle, $translation, $handle->
isFuzzy() );
262 $ttmserver->
update( $handle, $text );
277 $jobQueue = $this->jobQueueGroup->get( $this->getType() );
278 if ( !$delay || !$jobQueue->delayedJobsEnabled() ) {
281 $oldTime = $this->getReleaseTimestamp();
282 $newTime = time() + $delay;
283 if ( $oldTime !==
null && $oldTime >= $newTime ) {
286 $this->params[
'jobReleaseTimestamp' ] = $newTime;
298 static::WRITE_BACKOFF_EXPONENT + rand( 0, min( $errorCount, 4 ) )