Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/87695
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, 29 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MassMessage
refs/changes/95/87695/1
diff --git a/MassMessage.body.php b/MassMessage.body.php
index b799f6c..d1641ce 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 = ( $claimed - $abandoned );
+
+ $queued = $active + $pending;
+ return $queued;
+ }
}
diff --git a/MassMessage.hooks.php b/MassMessage.hooks.php
index 1d27ff1..ccdbebd 100644
--- a/MassMessage.hooks.php
+++ b/MassMessage.hooks.php
@@ -93,17 +93,18 @@
* @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 $module ApiQuerySiteInfo
+ * @param $result array
+ * @return bool
+ */
+ public static function onAPIQuerySiteInfoStatisticsInfo( $module,
&$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: newchange
Gerrit-Change-Id: Ibfa77ec33fbf4a1c1d4807b37ef4b2414e4afcad
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MassMessage
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits