jenkins-bot has submitted this change and it was merged. Change subject: Expose number of queued messages in the API ......................................................................
Expose number of queued messages in the API Move the code to get the number of queued messages to MassMessage::getQueuedCount(), and use the 'APIQuerySiteInfoStatisticsInfo' hook to add it. Depends on I712748077a0ac2fb729bfe3b6616ac4981cb754e in core. Change-Id: Ibfa77ec33fbf4a1c1d4807b37ef4b2414e4afcad --- M MassMessage.body.php M MassMessage.hooks.php M MassMessage.php 3 files changed, 28 insertions(+), 10 deletions(-) Approvals: Nikerabbit: Looks good to me, approved jenkins-bot: Verified diff --git a/MassMessage.body.php b/MassMessage.body.php index b799f6c..1c5a2bc 100644 --- a/MassMessage.body.php +++ b/MassMessage.body.php @@ -199,4 +199,21 @@ 'noparse' => false ); } + + /** + * Get the number of Queued messages on this site + * Taken from runJobs.php --group + * @return int + */ + public static function getQueuedCount() { + $group = JobQueueGroup::singleton(); + $queue = $group->get( 'massmessageJob' ); + $pending = $queue->getSize(); + $claimed = $queue->getAcquiredCount(); + $abandoned = $queue->getAbandonedCount(); + $active = max( $claimed - $abandoned, 0 ); + + $queued = $active + $pending; + return $queued; + } } diff --git a/MassMessage.hooks.php b/MassMessage.hooks.php index 1d27ff1..47659d1 100644 --- a/MassMessage.hooks.php +++ b/MassMessage.hooks.php @@ -93,17 +93,17 @@ * @return bool */ public static function onSpecialStatsAddExtra( &$extraStats ) { - // from runJobs.php --group - $group = JobQueueGroup::singleton(); - $queue = $group->get( 'massmessageJob' ); - $pending = $queue->getSize(); - $claimed = $queue->getAcquiredCount(); - $abandoned = $queue->getAbandonedCount(); - $active = ( $claimed - $abandoned ); + $extraStats['massmessage-queued-count'] = MassMessage::getQueuedCount(); + return true; + } - $queued = $active + $pending; - $extraStats['massmessage-queued-count'] = $queued; - + /** + * Add the number of queued messages to &meta=siteinfo&siprop=statistics + * @param $result array + * @return bool + */ + public static function onAPIQuerySiteInfoStatisticsInfo( &$result ) { + $result['queued-massmessages'] = MassMessage::getQueuedCount(); return true; } diff --git a/MassMessage.php b/MassMessage.php index 7695742..34acf90 100644 --- a/MassMessage.php +++ b/MassMessage.php @@ -65,6 +65,7 @@ $wgHooks['ParserFirstCallInit'][] = 'MassMessageHooks::onParserFirstCallInit'; $wgHooks['SpecialStatsAddExtra'][] = 'MassMessageHooks::onSpecialStatsAddExtra'; +$wgHooks['APIQuerySiteInfoStatisticsInfo'][] = 'MassMessageHooks::onAPIQuerySiteInfoStatisticsInfo'; $wgHooks['RenameUserPreRename'][] = 'MassMessageHooks::onRenameUserPreRename'; $wgHooks['UserGetReservedNames'][] = 'MassMessageHooks::onUserGetReservedNames'; $wgHooks['UnitTestsList'][] = 'MassMessageHooks::onUnitTestsList'; -- To view, visit https://gerrit.wikimedia.org/r/87695 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ibfa77ec33fbf4a1c1d4807b37ef4b2414e4afcad Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/MassMessage Gerrit-Branch: master Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits