Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry an initial channel produce failure #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 34 additions & 19 deletions lib/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,20 +466,30 @@ function Channel (base, options) {
* `operationCallback` is an object containing the `result` from the last
* operation attempt (or `null` if the operation was stopped prior to a
* final attempt).
* @param {Number} [maxRetries] - Maximum number of retries to attempt in
* the event of a failure. If no value is specified for this parameter,
* retries will be performed continuously until the operation succeeds or
* one of the terminal conditions mentioned above occurs.
* @private
*/
this._retryOnFailure = function (operationCallback, completeCallback) {
this._retryOnFailure = function (operationCallback, completeCallback,
maxRetries) {
if (!operationCallback) {
if (completeCallback) {
callbackAsync(completeCallback)
}
} else if (this._stillActive(completeCallback)) {
var operation = retry.operation({
var operationParams = {
factor: RETRY_FACTOR,
forever: true,
minTimeout: MIN_RETRY_TIMEOUT,
maxTimeout: MAX_RETRY_TIMEOUT
})
}
if (typeof maxRetries === 'undefined') {
operationParams.forever = true
} else {
operationParams.retries = maxRetries
}
var operation = retry.operation(operationParams)

operation.attempt(function () {
if (channel._stillActive(completeCallback)) {
Expand Down Expand Up @@ -1086,22 +1096,27 @@ Channel.prototype.delete = function (callback) {
* received from the streaming service for the produce attempt.
*/
Channel.prototype.produce = function (payload, callback) {
this._sendRequest(
this._request.post,
{
uri: util.appendUrlSubpath(this._producerPathPrefix, 'produce'),
json: true,
body: payload,
headers: {
'Content-Type': 'application/vnd.dxl.intel.records.v1+json'
}
},
function () {
if (callback) {
callback(null)
}
var channel = this
this._retryOnFailure(
function (retryCallback) {
channel._sendRequest(
channel._request.post,
{
uri: util.appendUrlSubpath(channel._producerPathPrefix, 'produce'),
json: true,
body: payload,
headers: {
'Content-Type': 'application/vnd.dxl.intel.records.v1+json'
}
},
function () {
retryCallback(null)
},
retryCallback
)
},
callback
callback,
1
)
}

Expand Down