azure-common
Advanced tools
Comparing version 0.9.0-pre.1 to 0.9.1-pre.2
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -1,65 +0,20 @@ | ||
// | ||
// Copyright (c) Microsoft and contributors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
/** | ||
* Copyright (c) Microsoft. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var _ = require('underscore'); | ||
var azureutil = require('../../util/util'); | ||
/** | ||
* Creates a new 'ExponentialRetryPolicyFilter' instance. | ||
* @class | ||
* The ExponentialRetryPolicyFilter allows you to retry operations, | ||
* using an exponential back-off interval between retries. | ||
* To apply a filter to service operations, use `withFilter` | ||
* and specify the filter to be used when creating a service. | ||
* @constructor | ||
* @param {number} [retryCount=3] The client retry count. | ||
* @param {number} [retryInterval=30000] The client retry interval, in milliseconds. | ||
* @param {number} [minRetryInterval=3000] The minimum retry interval, in milliseconds. | ||
* @param {number} [maxRetryInterval=90000] The maximum retry interval, in milliseconds. | ||
* | ||
* @example | ||
* var azure = require('azure'); | ||
* var retryOperations = new azure.ExponentialRetryPolicyFilter(); | ||
* var blobService = azure.createBlobService().withFilter(retryOperations) | ||
*/ | ||
function ExponentialRetryPolicyFilter(retryCount, retryInterval, minRetryInterval, maxRetryInterval) { | ||
this.retryCount = retryCount ? retryCount : ExponentialRetryPolicyFilter.DEFAULT_CLIENT_RETRY_COUNT; | ||
this.retryInterval = retryInterval ? retryInterval : ExponentialRetryPolicyFilter.DEFAULT_CLIENT_RETRY_INTERVAL; | ||
this.minRetryInterval = minRetryInterval ? minRetryInterval : ExponentialRetryPolicyFilter.DEFAULT_CLIENT_MIN_RETRY_INTERVAL; | ||
this.maxRetryInterval = maxRetryInterval ? maxRetryInterval : ExponentialRetryPolicyFilter.DEFAULT_CLIENT_MAX_RETRY_INTERVAL; | ||
} | ||
/** | ||
* Represents the default client retry interval, in milliseconds. | ||
*/ | ||
ExponentialRetryPolicyFilter.DEFAULT_CLIENT_RETRY_INTERVAL = 1000 * 30; | ||
/** | ||
* Represents the default client retry count. | ||
*/ | ||
ExponentialRetryPolicyFilter.DEFAULT_CLIENT_RETRY_COUNT = 3; | ||
/** | ||
* Represents the default maximum retry interval, in milliseconds. | ||
*/ | ||
ExponentialRetryPolicyFilter.DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1000 * 90; | ||
/** | ||
* Represents the default minimum retry interval, in milliseconds. | ||
*/ | ||
ExponentialRetryPolicyFilter.DEFAULT_CLIENT_MIN_RETRY_INTERVAL = 1000 * 3; | ||
/** | ||
* Determines if the operation should be retried and how long to wait until the next retry. | ||
@@ -71,3 +26,3 @@ * | ||
*/ | ||
ExponentialRetryPolicyFilter.prototype.shouldRetry = function (statusCode, retryData) { | ||
function shouldRetry(statusCode, retryData) { | ||
if (statusCode < 500) { | ||
@@ -80,3 +35,3 @@ return false; | ||
return (currentCount < this.retryCount); | ||
}; | ||
} | ||
@@ -90,3 +45,3 @@ /** | ||
*/ | ||
ExponentialRetryPolicyFilter.prototype.updateRetryData = function (retryData, err) { | ||
function updateRetryData (retryData, err) { | ||
if (!retryData) { | ||
@@ -118,4 +73,5 @@ retryData = { | ||
return retryData; | ||
}; | ||
} | ||
/** | ||
@@ -128,3 +84,3 @@ * Handles an operation with an exponential retry policy. | ||
*/ | ||
ExponentialRetryPolicyFilter.prototype.handle = function (requestOptions, next) { | ||
function handle(requestOptions, next) { | ||
var self = this; | ||
@@ -142,4 +98,6 @@ var retryData = null; | ||
if (returnObject.error && | ||
!azureutil.objectIsNull(returnObject.response) && | ||
self.shouldRetry(returnObject.response.statusCode, retryData)) { | ||
((!azureutil.objectIsNull(returnObject.response) && | ||
self.shouldRetry(returnObject.response.statusCode, retryData)) || | ||
returnObject.error.message === 'ETIMEDOUT' || | ||
returnObject.error.message === 'ESOCKETTIMEDOUT')) { | ||
@@ -150,7 +108,2 @@ // If previous operation ended with an error and the policy allows a retry, do that | ||
}, retryData.retryInterval); | ||
} else if (returnObject.error && (returnObject.error.message === 'ETIMEDOUT' || returnObject.error.message === 'ESOCKETTIMEDOUT')) { | ||
// Retry when time out | ||
setTimeout(function () { | ||
operation(); | ||
}, retryData.retryInterval); | ||
} else { | ||
@@ -173,4 +126,74 @@ if (!azureutil.objectIsNull(returnObject.error)) { | ||
operation(); | ||
}; | ||
} | ||
module.exports = ExponentialRetryPolicyFilter; | ||
/** | ||
* Creates a new 'ExponentialRetryPolicyFilter' instance. | ||
* | ||
* @constructor | ||
* @param {number} retryCount The client retry count. | ||
* @param {number} retryInterval The client retry interval, in milliseconds. | ||
* @param {number} minRetryInterval The minimum retry interval, in milliseconds. | ||
* @param {number} maxRetryInterval The maximum retry interval, in milliseconds. | ||
*/ | ||
function ExponentialRetryPolicyFilter(retryCount, retryInterval, minRetryInterval, maxRetryInterval) { | ||
// Implement the new style filter in terms of the old implementation | ||
function newFilter(options, next, callback) { | ||
var retryData = null; | ||
function retryCallback(err, result, response, body) { | ||
retryData = newFilter.updateRetryData(retryData, err); | ||
if (err && | ||
!azureutil.objectIsNull(response) && | ||
newFilter.shouldRetry(response.statusCode, retryData)) { | ||
// If previous operation ended with an error and the policy allows a retry, do that | ||
setTimeout(function () { | ||
next(options, retryCallback); | ||
}, retryData.retryInterval); | ||
} else { | ||
if (!azureutil.objectIsNull(err)) { | ||
// If the operation failed in the end, return all errors instead of just the last one | ||
err = retryData.error; | ||
} | ||
callback(err, result, response, body); | ||
} | ||
} | ||
return next(options, retryCallback); | ||
} | ||
_.extend(newFilter, { | ||
retryCount: retryCount || ExponentialRetryPolicyFilter.DEFAULT_CLIENT_RETRY_COUNT, | ||
retryInterval: retryInterval || ExponentialRetryPolicyFilter.DEFAULT_CLIENT_RETRY_INTERVAL, | ||
minRetryInterval: minRetryInterval || ExponentialRetryPolicyFilter.DEFAULT_CLIENT_MIN_RETRY_INTERVAL, | ||
maxRetryInterval: maxRetryInterval || ExponentialRetryPolicyFilter.DEFAULT_CLIENT_MAX_RETRY_INTERVAL, | ||
handle: handle, | ||
shouldRetry: shouldRetry, | ||
updateRetryData: updateRetryData | ||
}); | ||
return newFilter; | ||
} | ||
/** | ||
* Represents the default client retry interval, in milliseconds. | ||
*/ | ||
ExponentialRetryPolicyFilter.DEFAULT_CLIENT_RETRY_INTERVAL = 1000 * 30; | ||
/** | ||
* Represents the default client retry count. | ||
*/ | ||
ExponentialRetryPolicyFilter.DEFAULT_CLIENT_RETRY_COUNT = 3; | ||
/** | ||
* Represents the default maximum retry interval, in milliseconds. | ||
*/ | ||
ExponentialRetryPolicyFilter.DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1000 * 90; | ||
/** | ||
* Represents the default minimum retry interval, in milliseconds. | ||
*/ | ||
ExponentialRetryPolicyFilter.DEFAULT_CLIENT_MIN_RETRY_INTERVAL = 1000 * 3; | ||
module.exports = ExponentialRetryPolicyFilter; |
@@ -1,51 +0,20 @@ | ||
// | ||
// Copyright (c) Microsoft and contributors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
var azureutil = require('../../util/util'); | ||
/** | ||
* Creates a new LinearRetryPolicyFilter instance. | ||
* @class | ||
* The LinearRetryPolicyFilter allows you to retry operations, | ||
* using an linear back-off interval between retries. | ||
* To apply a filter to service operations, use `withFilter` | ||
* and specify the filter to be used when creating a service. | ||
* @constructor | ||
* @param {number} [retryCount=30000] The client retry count. | ||
* @param {number} [retryInterval=3] The client retry interval, in milliseconds. | ||
/** | ||
* Copyright (c) Microsoft. All rights reserved. | ||
* | ||
* @example | ||
* var azure = require('azure'); | ||
* var retryOperations = new azure.LinearRetryPolicyFilter(); | ||
* var blobService = azure.createBlobService().withFilter(retryOperations) | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
function LinearRetryPolicyFilter(retryCount, retryInterval) { | ||
this.retryCount = retryCount ? retryCount : LinearRetryPolicyFilter.DEFAULT_CLIENT_RETRY_COUNT; | ||
this.retryInterval = retryInterval ? retryInterval : LinearRetryPolicyFilter.DEFAULT_CLIENT_RETRY_INTERVAL; | ||
} | ||
/** | ||
* Represents the default client retry interval, in milliseconds. | ||
*/ | ||
LinearRetryPolicyFilter.DEFAULT_CLIENT_RETRY_INTERVAL = 1000 * 30; | ||
var _ = require('underscore'); | ||
var azureutil = require('../../util/util'); | ||
/** | ||
* Represents the default client retry count. | ||
*/ | ||
LinearRetryPolicyFilter.DEFAULT_CLIENT_RETRY_COUNT = 3; | ||
/** | ||
* Determines if the operation should be retried and how long to wait until the next retry. | ||
@@ -57,4 +26,4 @@ * | ||
*/ | ||
LinearRetryPolicyFilter.prototype.shouldRetry = function (statusCode, retryData) { | ||
if (statusCode < 500) { | ||
function shouldRetry(statusCode, retryData) { | ||
if (statusCode >= 400 && statusCode < 500) { | ||
return false; | ||
@@ -66,3 +35,3 @@ } | ||
return (currentCount < this.retryCount); | ||
}; | ||
} | ||
@@ -76,3 +45,3 @@ /** | ||
*/ | ||
LinearRetryPolicyFilter.prototype.updateRetryData = function (retryData, err) { | ||
function updateRetryData(retryData, err) { | ||
if (!retryData) { | ||
@@ -96,3 +65,3 @@ retryData = { | ||
return retryData; | ||
}; | ||
} | ||
@@ -106,5 +75,5 @@ /** | ||
*/ | ||
LinearRetryPolicyFilter.prototype.handle = function (requestOptions, next) { | ||
function handle(requestOptions, next) { | ||
var retryData = null; | ||
var self = this; | ||
var retryData = null; | ||
@@ -120,4 +89,6 @@ var operation = function () { | ||
if (returnObject.error && | ||
!azureutil.objectIsNull(returnObject.response) && | ||
self.shouldRetry(returnObject.response.statusCode, retryData)) { | ||
((!azureutil.objectIsNull(returnObject.response) && | ||
self.shouldRetry(returnObject.response.statusCode, retryData)) || | ||
returnObject.error.message === 'ETIMEDOUT' || | ||
returnObject.error.message === 'ESOCKETTIMEDOUT')) { | ||
@@ -128,7 +99,2 @@ // If previous operation ended with an error and the policy allows a retry, do that | ||
}, retryData.retryInterval); | ||
} else if (returnObject.error && (returnObject.error.message === 'ETIMEDOUT' || returnObject.error.message === 'ESOCKETTIMEDOUT')) { | ||
// Retry when time out | ||
setTimeout(function () { | ||
operation(); | ||
}, retryData.retryInterval); | ||
} else { | ||
@@ -151,4 +117,58 @@ if (!azureutil.objectIsNull(returnObject.error)) { | ||
operation(); | ||
}; | ||
} | ||
module.exports = LinearRetryPolicyFilter; | ||
/** | ||
* Creates a new LinearRetryPolicyFilter instance. | ||
* | ||
* @constructor | ||
* @param {number} retryCount The client retry count. | ||
* @param {number} retryInterval The client retry interval, in milliseconds. | ||
*/ | ||
function LinearRetryPolicyFilter(retryCount, retryInterval) { | ||
// Implement the new style filter in terms of the old implementation | ||
function newFilter(options, next, callback) { | ||
var retryData = null; | ||
function retryCallback(err, result, response, body) { | ||
retryData = newFilter.updateRetryData(retryData, err); | ||
if (err && | ||
!azureutil.objectIsNull(response) && | ||
newFilter.shouldRetry(response.statusCode, retryData)) { | ||
// If previous operation ended with an error and the policy allows a retry, do that | ||
setTimeout(function () { | ||
next(options, retryCallback); | ||
}, retryData.retryInterval); | ||
} else { | ||
if (!azureutil.objectIsNull(err)) { | ||
// If the operation failed in the end, return all errors instead of just the last one | ||
err = retryData.error; | ||
} | ||
callback(err, result, response, body); | ||
} | ||
} | ||
return next(options, retryCallback); | ||
} | ||
_.extend(newFilter, { | ||
retryCount: retryCount || LinearRetryPolicyFilter.DEFAULT_CLIENT_RETRY_COUNT, | ||
retryInterval: retryInterval || LinearRetryPolicyFilter.DEFAULT_CLIENT_RETRY_INTERVAL, | ||
handle: handle, | ||
shouldRetry: shouldRetry, | ||
updateRetryData: updateRetryData | ||
}); | ||
return newFilter; | ||
} | ||
/** | ||
* Represents the default client retry interval, in milliseconds. | ||
*/ | ||
LinearRetryPolicyFilter.DEFAULT_CLIENT_RETRY_INTERVAL = 1000 * 30; | ||
/** | ||
* Represents the default client retry count. | ||
*/ | ||
LinearRetryPolicyFilter.DEFAULT_CLIENT_RETRY_COUNT = 3; | ||
module.exports = LinearRetryPolicyFilter; |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -26,2 +26,3 @@ // | ||
var SigningFilter = require('./filters/signingfilter'); | ||
var RedirectFilter = require('./filters/redirectfilter'); | ||
@@ -43,2 +44,3 @@ var ServiceClientConstants = require('./serviceclientconstants'); | ||
filters.push(ErrorHandlingFilter.create()); | ||
filters.push(RedirectFilter.create()); | ||
@@ -45,0 +47,0 @@ this.pipeline = requestPipeline.create.apply(requestPipeline, filters); |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ // |
@@ -0,0 +0,0 @@ Apache License |
@@ -13,3 +13,3 @@ { | ||
], | ||
"version": "0.9.0-pre.1", | ||
"version": "0.9.1-pre.2", | ||
"description": "Windows Azure Common Client Library for node", | ||
@@ -16,0 +16,0 @@ "tags": [ |
@@ -0,0 +0,0 @@ # Windows Azure SDK for Node.js - Common |
285827
42
8202