Legoktm has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/394407 )

Change subject: [WIP] Use PoolCounter to rate limit requests to the ORES service
......................................................................

[WIP] Use PoolCounter to rate limit requests to the ORES service

Change-Id: Id7a58e9ef0d136a86bde7902f795cda6d9a14721
---
M includes/Api.php
1 file changed, 31 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ORES 
refs/changes/07/394407/1

diff --git a/includes/Api.php b/includes/Api.php
index 7543d1d..e64ce11 100644
--- a/includes/Api.php
+++ b/includes/Api.php
@@ -19,8 +19,10 @@
 use FormatJson;
 use MediaWiki\Logger\LoggerFactory;
 use MWHttpRequest;
+use PoolCounterWorkViaCallback;
 use RequestContext;
 use RuntimeException;
+use Status;
 use WebRequest;
 
 /**
@@ -88,14 +90,39 @@
                $url = $this->getUrl();
                $params['format'] = 'json';
                $url = wfAppendQuery( $url, $params );
-               $logger->debug( "Requesting: {$url}" );
-               $req = MWHttpRequest::factory( $url, 
$this->getMWHttpRequestOptions(), __METHOD__ );
-               $status = $req->execute();
+               $options = $this->getMWHttpRequestOptions();
+               $work = new PoolCounterWorkViaCallback(
+                       'ORES',
+                       sha1( $url ),
+                       [
+                               'doWork' => function() use ( $url, $options, 
$logger ) {
+                                       $logger->debug( "Requesting: {$url}" );
+                                       $req = MWHttpRequest::factory(
+                                               $url,
+                                               $options,
+                                               __METHOD__
+                                       );
+                                       $status = $req->execute();
+                                       if ( !$status->isOK() ) {
+                                               return $status;
+                                       }
+
+                                       return Status::newGood( 
$req->getContent() );
+                               },
+                               'error' => function( Status $status ) {
+                                       // Pass through
+                                       return $status;
+                               },
+                       ]
+               );
+
+               /** @var Status $status */
+               $status = $work->execute();
                if ( !$status->isOK() ) {
                        throw new RuntimeException( "Failed to make ORES 
request to [{$url}], "
                                . $status->getMessage()->text() );
                }
-               $json = $req->getContent();
+               $json = $status->getValue();
                $logger->debug( "Raw response: {$json}" );
                $data = FormatJson::decode( $json, true );
                if ( !$data || !empty( $data['error'] ) ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/394407
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id7a58e9ef0d136a86bde7902f795cda6d9a14721
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Legoktm <lego...@member.fsf.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to