Skip to content

Commit

Permalink
Merge pull request #4 from muguang-lijing/master
Browse files Browse the repository at this point in the history
fix api request timeout
  • Loading branch information
calvinxiao authored Oct 27, 2016
2 parents 06c624a + f19b0a6 commit 3609797
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ language: node_js
node_js:
- '4.2.2'

before_script:
- npm install

script: "npm test"
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"

after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
3 changes: 2 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var config = {
httpProtocol: httpProtocol,
appHost: appHost,
apiHost: apiHost,
requestLimit: 40
requestLimit: 40,
requestTimeout: 510
};
module.exports = config;
4 changes: 2 additions & 2 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var querystring = require('querystring'),

var request = function(options, params, callback) {
if (requestCount == config.requestLimit) {
setTimeout(request, 500, options, params, callback);
setTimeout(request, config.requestTimeout, options, params, callback);
return;
}
requestCount++;
Expand All @@ -20,7 +20,7 @@ var request = function(options, params, callback) {
} catch (err) {
callback(err);
} finally {
setTimeout(fnReduceRequestCount, config.requestLimit * 500 * eval(res.headers['x-yhsd-shop-api-call-limit']));
setTimeout(fnReduceRequestCount, config.requestLimit * config.requestTimeout * eval(res.headers['x-yhsd-shop-api-call-limit']));
}
callback(null, data);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yhsd-api",
"version": "1.0.4",
"version": "1.0.5",
"description": "Youhaosuda API SDK for node.",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit 3609797

Please sign in to comment.