20 public function __construct() {
21 parent::__construct();
22 $this->addDescription(
23 'Check and run RebuildMessageIndex and MessageGroupStats update once ' .
24 'UpdateMessageJobs are done. Intended to be run periodically'
26 $this->requireExtension(
'Translate' );
29 public function execute() {
30 $mwServices = MediaWikiServices::getInstance();
31 $config = $mwServices->getMainConfig();
33 if ( !$config->get(
'TranslateGroupSynchronizationCache' ) ) {
34 $this->fatalError(
'GroupSynchronizationCache is not enabled' );
37 $logger = LoggerFactory::getInstance(
'Translate.GroupSynchronization' );
38 $groupSyncCache = Services::getInstance()->getGroupSynchronizationCache();
39 $groupsInSync = $groupSyncCache->getGroupsInSync();
40 if ( !$groupsInSync ) {
41 $logger->debug(
'Nothing to synchronize' );
42 $this->printSummaryInfo( $groupSyncCache, $logger, $groupsInSync );
47 'Group synchronization is in progress for {count} groups. Checking latest status...',
48 [
'count' => count( $groupsInSync ) ]
51 $groupsInProgress = [];
52 foreach ( $groupsInSync as $groupId ) {
53 $groupResponse = $groupSyncCache->getSynchronizationStatus( $groupId );
55 if ( $groupResponse->isDone() ) {
56 $groupSyncCache->endSync( $groupId );
60 if ( $groupResponse->hasTimedOut() ) {
61 $remainingMessages = $groupResponse->getRemainingMessages();
63 'UpdateMessageJobs timed out for group - {groupId}; ' .
64 'Messages - {messages}; ' .
65 'Jobs remaining - {jobRemaining}',
67 'groupId' => $groupId,
68 'jobRemaining' => count( $remainingMessages ),
69 'messages' => implode(
', ', array_keys( $remainingMessages ) )
73 $count = count( $remainingMessages );
74 wfLogWarning(
"UpdateMessageJob timed out for group $groupId with $count message(s) remaining" );
75 $groupSyncCache->forceEndSync( $groupId );
77 $groupSyncCache->addGroupErrors( $groupResponse );
80 $groupsInProgress[] = $groupId;
84 if ( !$groupsInProgress ) {
86 $logger->info(
'All message groups are now in sync.' );
87 $mwServices->getJobQueueGroup()->push( RebuildMessageIndexJob::newJob() );
90 $logger->info(
"Script completed successfully." );
91 $this->printSummaryInfo( $groupSyncCache, $logger, $groupsInProgress );
94 private function printSummaryInfo(
96 LoggerInterface $logger,
99 $summaryMessage = [
'Current group sync summary:' ];
102 $summaryMessage[] =
'{syncCount} in sync: {syncGroups}';
103 $summaryParams[
'syncCount' ] = count( $groupsInSync );
104 $summaryParams[
'syncGroups' ] = $groupsInSync ? implode(
', ', $groupsInSync ) :
'N/A';
107 $summaryMessage[] =
'{reviewCount} in review: {reviewGroups}';
108 $summaryParams[
'reviewCount' ] = count( $groupsInReview );
109 $summaryParams[
'reviewGroups' ] = $groupsInReview ? implode(
', ', $groupsInReview ) :
'N/A';
112 $summaryMessage[] =
'{errorCount} with errors: {errorGroups}';
113 $summaryParams[
'errorCount' ] = count( $groupsWithError );
114 $summaryParams[
'errorGroups' ] = $groupsWithError ? implode(
', ', $groupsWithError ) :
'N/A';
117 implode(
'; ', $summaryMessage ),