Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MessageIndexRebuildJob.php
Go to the documentation of this file.
1<?php
12use MediaWiki\MediaWikiServices;
13
21 public static function newJob() {
22 $timestamp = microtime( true );
23 $job = new self( Title::newMainPage(), [ 'timestamp' => $timestamp ] );
24
25 return $job;
26 }
27
32 public function __construct( $title, $params = [] ) {
33 parent::__construct( __CLASS__, $title, $params );
34 $this->removeDuplicates = true;
35 }
36
37 public function run() {
38 // Make sure we have latest version of message groups from global cache.
39 // This should be pretty fast, just a few cache fetches with some post processing.
40 MessageGroups::singleton()->clearProcessCache();
41
42 // BC for existing jobs which may not have this parameter set
43 $timestamp = $this->getParams()['timestamp'] ?? microtime( true );
44
45 try {
46 MessageIndex::singleton()->rebuild( $timestamp );
47 } catch ( MessageIndexException $e ) {
48 // Currently there is just one type of exception: lock wait time exceeded.
49 // Assuming no bugs, this is a transient issue and retry will solve it.
50 $this->logWarning( $e->getMessage() );
51 // Try again later. See ::allowRetries
52 return false;
53 }
54
55 return true;
56 }
57
59 public function allowRetries() {
60 // This is the default, but added for explicitness and clarity
61 return true;
62 }
63
65 public function getDeduplicationInfo() {
66 $info = parent::getDeduplicationInfo();
67 // The timestamp is different for every job, so ignore it. The worst that can
68 // happen is that the front cache is not cleared until a future job is created.
69 // There is a check in MessageIndex to spawn a new job if timestamp is smaller
70 // than expected.
71 //
72 // Ideally we would take the latest timestamp, but it seems that the job queue
73 // just prevents insertion of duplicate jobs instead.
74 unset( $info['params']['timestamp'] );
75
76 return $info;
77 }
78
80 public function insertIntoJobQueue(): void {
81 MediaWikiServices::getInstance()->getJobQueueGroup()->push( $this );
82 }
83}
Job for rebuilding message index.
__construct( $title, $params=[])