Skip to content

Adds backoff / retry to HTTP calls. #545

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

Merged
merged 4 commits into from
Jan 9, 2018
Merged

Adds backoff / retry to HTTP calls. #545

merged 4 commits into from
Jan 9, 2018

Conversation

gguuss
Copy link
Contributor

@gguuss gguuss commented Jan 5, 2018

No description provided.

@codecov
Copy link

codecov bot commented Jan 5, 2018

Codecov Report

Merging #545 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #545   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           1      1           
  Lines           3      3           
=====================================
  Hits            3      3

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5cb34c0...be80033. Read the comment docs.

"jsonwebtoken": "7.4.1",
"request": "2.82.0",
"uuid": "3.1.0"
"requestretry": "requestretry",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a SemVer number? e.g. 1.12.2, the latest version of the library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched.

@@ -182,6 +201,21 @@ function publishAsync (authToken, messageCount, numMessages) {
// [START iot_http_getconfig]
function getConfig (authToken, version) {
console.log(`Getting config from URL: ${urlBase}`);

// Custom backoff functions
function retryNotSuccess (err, response, body) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a library that comes with these built-in? (Perhaps nodejs-repo-tools?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, switched to recommended library that uses built-in exponential backoff.

@@ -141,16 +141,35 @@ function publishAsync (authToken, messageCount, numMessages) {
binary_data: binaryData
}
};

// Custom backoff functions
function retryNotSuccess (err, response, body) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto to below comment - can these come from a library?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, switched to recommended library that uses built-in exponential backoff.

Copy link
Contributor

@ace-n ace-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once nits are fixed. 👍

};

// Send events for high-frequency updates, update state only occasionally.
const delayMs = argv.messageType === 'events' ? 1000 : 2000;
request.post(options, function (error, response, body) {
console.log(JSON.stringify(request));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended?

@@ -17,7 +17,7 @@
// [START iot_http_includes]
const fs = require('fs');
const jwt = require('jsonwebtoken');
const request = require('requestretry');
const request = require('retry-request');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we name this something other than request (to avoid confusion with the library of the same name)? Maybe retryRequest?

function (incomingHttpMessage) {
console.log('Retry?');
return incomingHttpMessage.statusMessage !== 'OK';
}
};
console.log(JSON.stringify(request.RetryStrategies));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto - is this intended?

};
console.log(JSON.stringify(request.RetryStrategies));
request.get(options, function (error, response, body) {
request(options, function (error, response, body) {
Copy link
Contributor

@ace-n ace-n Jan 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: arrow function?

(Apply this comment throughout your PR if you decide to make any changes.)

@gguuss gguuss merged commit fbb2f8a into master Jan 9, 2018
@gguuss gguuss deleted the exponential-backoff branch February 26, 2018 19:13
grayside pushed a commit that referenced this pull request Oct 26, 2022
grayside pushed a commit that referenced this pull request Nov 3, 2022
ace-n pushed a commit that referenced this pull request Nov 16, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
ace-n pushed a commit that referenced this pull request Nov 17, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
ace-n pushed a commit that referenced this pull request Nov 17, 2022
ace-n pushed a commit that referenced this pull request Nov 17, 2022
ahrarmonsur pushed a commit that referenced this pull request Nov 17, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
ace-n pushed a commit that referenced this pull request Nov 17, 2022
ace-n pushed a commit that referenced this pull request Nov 17, 2022
ace-n pushed a commit that referenced this pull request Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants