21 public function __construct() {
22 parent::__construct();
23 $this->addDescription(
24 'Check and run RebuildMessageIndex and MessageGroupStats update once ' .
25 'UpdateMessageJobs are done. Intended to be run periodically'
27 $this->requireExtension(
'Translate' );
30 public function execute() {
31 $mwServices = MediaWikiServices::getInstance();
32 $config = $mwServices->getMainConfig();
34 if ( !$config->get(
'TranslateGroupSynchronizationCache' ) ) {
35 $this->fatalError(
'GroupSynchronizationCache is not enabled' );
39 $groupSyncCache = Services::getInstance()->getGroupSynchronizationCache();
40 $groupsInSync = $groupSyncCache->getGroupsInSync();
41 if ( !$groupsInSync ) {
42 $logger->debug(
'Nothing to synchronize' );
43 $this->printSummaryInfo( $groupSyncCache, $logger, $groupsInSync );
48 'Group synchronization is in progress for {count} groups. Checking latest status...',
49 [
'count' => count( $groupsInSync ) ]
52 $groupsInProgress = [];
53 foreach ( $groupsInSync as $groupId ) {
54 $groupResponse = $groupSyncCache->getSynchronizationStatus( $groupId );
56 if ( $groupResponse->isDone() ) {
57 $groupSyncCache->endSync( $groupId );
61 if ( $groupResponse->hasTimedOut() ) {
62 $remainingMessages = $groupResponse->getRemainingMessages();
64 'UpdateMessageJobs timed out for group - {groupId}; ' .
65 'Messages - {messages}; ' .
66 'Jobs remaining - {jobRemaining}',
68 'groupId' => $groupId,
69 'jobRemaining' => count( $remainingMessages ),
70 'messages' => implode(
', ', array_keys( $remainingMessages ) )
74 $count = count( $remainingMessages );
75 wfLogWarning(
"UpdateMessageJob timed out for group $groupId with $count message(s) remaining" );
76 $groupSyncCache->forceEndSync( $groupId );
78 $groupSyncCache->addGroupErrors( $groupResponse );
81 $groupsInProgress[] = $groupId;
85 if ( !$groupsInProgress ) {
87 $logger->info(
'All message groups are now in sync.' );
88 $mwServices->getJobQueueGroup()->push( RebuildMessageIndexJob::newJob() );
91 $logger->info(
"Script completed successfully." );
92 $this->printSummaryInfo( $groupSyncCache, $logger, $groupsInProgress );
95 private function printSummaryInfo(
97 LoggerInterface $logger,
100 $summaryMessage = [
'Current group sync summary:' ];
103 $summaryMessage[] =
'{syncCount} in sync: {syncGroups}';
104 $summaryParams[
'syncCount' ] = count( $groupsInSync );
105 $summaryParams[
'syncGroups' ] = $groupsInSync ? implode(
', ', $groupsInSync ) :
'N/A';
108 $summaryMessage[] =
'{reviewCount} in review: {reviewGroups}';
109 $summaryParams[
'reviewCount' ] = count( $groupsInReview );
110 $summaryParams[
'reviewGroups' ] = $groupsInReview ? implode(
', ', $groupsInReview ) :
'N/A';
113 $summaryMessage[] =
'{errorCount} with errors: {errorGroups}';
114 $summaryParams[
'errorCount' ] = count( $groupsWithError );
115 $summaryParams[
'errorGroups' ] = $groupsWithError ? implode(
', ', $groupsWithError ) :
'N/A';
118 implode(
'; ', $summaryMessage ),