19 public function __construct() {
20 parent::__construct();
21 $this->addDescription(
22 'Check and run MessageIndexRebuild and MessageGroupStats update once ' .
23 'MessageUpdateJobs are done. Intended to be run periodically'
25 $this->requireExtension(
'Translate' );
28 public function execute() {
29 $mwServices = MediaWikiServices::getInstance();
30 $config = $mwServices->getMainConfig();
32 if ( !$config->get(
'TranslateGroupSynchronizationCache' ) ) {
33 $this->fatalError(
'GroupSynchronizationCache is not enabled' );
36 $logger = LoggerFactory::getInstance(
'Translate.GroupSynchronization' );
37 $groupSyncCache = Services::getInstance()->getGroupSynchronizationCache();
38 $groupsInSync = $groupSyncCache->getGroupsInSync();
39 if ( !$groupsInSync ) {
40 $logger->info(
'All message groups are in sync' );
44 $logger->info(
'Group synchronization is in progress' );
46 $groupsInProgress = [];
47 foreach ( $groupsInSync as $groupId ) {
48 $groupResponse = $groupSyncCache->getSynchronizationStatus( $groupId );
50 if ( $groupResponse->isDone() ) {
51 $groupSyncCache->endSync( $groupId );
55 if ( $groupResponse->hasTimedOut() ) {
56 $remainingMessages = $groupResponse->getRemainingMessages();
58 'MessageUpdateJobs timed out for group - {groupId}; ' .
59 'Messages - {messages}; ' .
60 'Jobs remaining - {jobRemaining}',
62 'groupId' => $groupId ,
63 'jobRemaining' => count( $remainingMessages ),
64 'messages' => implode(
', ', array_keys( $remainingMessages ) )
68 $count = count( $remainingMessages );
69 wfLogWarning(
"MessageUpdateJob timed out for group $groupId with $count message(s) remaining" );
70 $groupSyncCache->forceEndSync( $groupId );
72 $groupSyncCache->addGroupErrors( $groupResponse );
75 $groupsInProgress[] = $groupId;
79 if ( !$groupsInProgress ) {
81 $logger->info(
'All message groups are now in sync.' );
82 $mwServices->getJobQueueGroup()->push( MessageIndexRebuildJob::newJob() );
86 "Script completed successfully. " .
87 "{inProgressGroupCount} group synchronization(s) is/are in progress",
89 'inProgressGroupCount' => count( $groupsInProgress )