YUKI Hiroshi
null+****@clear*****
Mon Apr 20 14:57:28 JST 2015
YUKI Hiroshi 2015-04-20 14:57:28 +0900 (Mon, 20 Apr 2015) New Revision: de814293b45045290098776589dffbe8e2e7f6ac https://github.com/droonga/express-droonga/commit/de814293b45045290098776589dffbe8e2e7f6ac Message: Report GATEWAY TIMEOUT error after 1 minute Modified files: lib/adapter/http.js Modified: lib/adapter/http.js (+18 -4) =================================================================== --- lib/adapter/http.js 2015-04-20 14:55:40 +0900 (527d7dc) +++ lib/adapter/http.js 2015-04-20 14:57:28 +0900 (f90f23c) @@ -4,8 +4,10 @@ var api = require('./api'); var ConsoleLogger = require('../console-logger').ConsoleLogger; var CONNECTION_RETRY_INTERVAL = 1000; +var MAX_RETRY_COUNT = 60; var ERROR_INTERNAL = 500; +var ERROR_GATEWAY_TIMEOUT = 504; function createRequestResponseHandler(params) { params = params || {}; @@ -41,7 +43,7 @@ function createRequestResponseHandler(params) { } } - var processRequest = function(error) { + var processRequest = function(error, retryCount) { if (error) { var errorBody = { error: error.message @@ -55,9 +57,15 @@ function createRequestResponseHandler(params) { if (!connection) { // When the cluster members are changing, we cannot get // actual connection for a member, so retry later. + retryCount = retryCount || 0; + if (retryCount >= MAX_RETRY_COUNT) { + response.status(ERROR_GATEWAY_TIMEOUT).jsonp(null); + } + else { setTimeout(function() { - processRequest(); + processRequest(null, retryCount + 1); }, CONNECTION_RETRY_INTERVAL); + } return; } var wrappedConnection = new wrapper.DroongaProtocolConnectionWrapper(connection, callback, options); @@ -97,7 +105,7 @@ function createGenericHandler(params) { if (typeof timeout != 'undefined') options.timeout = timeout; - var processRequest = function(error) { + var processRequest = function(error, retryCount) { if (error) { var errorBody = { error: error.message @@ -111,9 +119,15 @@ function createGenericHandler(params) { if (!connection) { // When the cluster members are changing, we cannot get // actual connection for a member, so retry later. + retryCount = retryCount || 0; + if (retryCount >= MAX_RETRY_COUNT) { + response.status(ERROR_GATEWAY_TIMEOUT).jsonp(null); + } + else { setTimeout(function() { - processRequest(); + processRequest(null, retryCount + 1); }, CONNECTION_RETRY_INTERVAL); + } return; } -------------- next part -------------- HTML����������������������������...Download