Node.js http retry do while mechanism The Next CEO of Stack OverflowNode.JS HTTP server...
How to write papers efficiently when English isn't my first language?
How do scammers retract money, while you can’t?
Is a stroke of luck acceptable after a series of unfavorable events?
Customer Requests (Sometimes) Drive Me Bonkers!
Grabbing quick drinks
How easy is it to start Magic from scratch?
How can a function with a hole (removable discontinuity) equal a function with no hole?
Return of the Riley Riddles in Reverse
In place solution to remove duplicates from a sorted list
Why doesn't a table tennis ball float on the surface? How do we calculate buoyancy here?
% symbol leads to superlong (forever?) compilations
Creating a generator function for a large data set for a neural network
Is expanding the research of a group into machine learning as a PhD student risky?
What does "colonia" and "interior/dpto" means in Mexico on address lines?
ls Ordering[Ordering[list]] optimal?
Why use "finir par" instead of "finir de" before an infinitive?
What does "Its cash flow is deeply negative" mean?
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
How long to clear the 'suck zone' of a turbofan after start is initiated?
Overlapping nodes in a decision tree
How do I construct this japanese bowl?
How do I go from 300 unfinished/half written blog posts, to published posts?
Is the destination of a commercial flight important for the pilot?
How to be diplomatic in refusing to write code that breaches the privacy of our users
Node.js http retry do while mechanism
The Next CEO of Stack OverflowNode.JS HTTP server displaying GoogleAJAX call to make an HTTP requestRetry storing HTTP response into a variable until specific code'Retry' mechanism with callbackNode.JS HTTP shortcut wrapperNode.js Sequelize PromiseNode.js error handling using merely if else without try catchGolang HTTP request retry codeMechanism to retry failed requests, with throttlingNode.js HTTP server with request logging
$begingroup$
I have implemented a simple do/while loop to handle a http request to a third-party. I don’t know when the data I receive will have elements in its array so I retry up to 10 times until the array given to me has data which then I stop and store the data in my database.
My question is in terms of performance is my API going to be affected by having this retry mechanism using a simple do/while loop? If so what is a better way to implement a retry mechanism like this??
public MAX_RETRY = 10;
public async processMetrics(sessionId: any, side: any): Promise <any> {
try {
let metrics;
let retryAttempts = 0;
do {
await new Promise((done) => setTimeout(done, 2000));
metrics = await this.getMetrics(session._id, sessionRequest._id);
retryAttempts++;
} while (!metrics.body.metrics.length && (retryAttempts < this.MAX_RETRY));
// Store in DB
} catch (err) {
}
}
public async getMetrics(sessionId: any, requestId: any): Promise <any> {
const url = this.config.backendUrl + "/check/metrics";
const options = {
uri: url,
headers: {
"X-IDCHECK-SESSION_ID": sessionId,
},
body: {},
json: true,
resolveWithFullResponse: true,
};
const metrics = await request.get(options);
return metrics;
}
I am calling processMetrics from a different async function. processMetrics is calling a backend (getMetrics) every 2 seconds, it will retry 10 times to see if the result is ready. If it is I will store something in the database and then return.
javascript node.js error-handling http express.js
$endgroup$
add a comment |
$begingroup$
I have implemented a simple do/while loop to handle a http request to a third-party. I don’t know when the data I receive will have elements in its array so I retry up to 10 times until the array given to me has data which then I stop and store the data in my database.
My question is in terms of performance is my API going to be affected by having this retry mechanism using a simple do/while loop? If so what is a better way to implement a retry mechanism like this??
public MAX_RETRY = 10;
public async processMetrics(sessionId: any, side: any): Promise <any> {
try {
let metrics;
let retryAttempts = 0;
do {
await new Promise((done) => setTimeout(done, 2000));
metrics = await this.getMetrics(session._id, sessionRequest._id);
retryAttempts++;
} while (!metrics.body.metrics.length && (retryAttempts < this.MAX_RETRY));
// Store in DB
} catch (err) {
}
}
public async getMetrics(sessionId: any, requestId: any): Promise <any> {
const url = this.config.backendUrl + "/check/metrics";
const options = {
uri: url,
headers: {
"X-IDCHECK-SESSION_ID": sessionId,
},
body: {},
json: true,
resolveWithFullResponse: true,
};
const metrics = await request.get(options);
return metrics;
}
I am calling processMetrics from a different async function. processMetrics is calling a backend (getMetrics) every 2 seconds, it will retry 10 times to see if the result is ready. If it is I will store something in the database and then return.
javascript node.js error-handling http express.js
$endgroup$
$begingroup$
So this seems to be within the context of a class. You should include the entire class for review so full context can be seen. Also this appears to be Typescript, so you should ad that to your tags.
$endgroup$
– Mike Brant
Mar 18 at 21:33
add a comment |
$begingroup$
I have implemented a simple do/while loop to handle a http request to a third-party. I don’t know when the data I receive will have elements in its array so I retry up to 10 times until the array given to me has data which then I stop and store the data in my database.
My question is in terms of performance is my API going to be affected by having this retry mechanism using a simple do/while loop? If so what is a better way to implement a retry mechanism like this??
public MAX_RETRY = 10;
public async processMetrics(sessionId: any, side: any): Promise <any> {
try {
let metrics;
let retryAttempts = 0;
do {
await new Promise((done) => setTimeout(done, 2000));
metrics = await this.getMetrics(session._id, sessionRequest._id);
retryAttempts++;
} while (!metrics.body.metrics.length && (retryAttempts < this.MAX_RETRY));
// Store in DB
} catch (err) {
}
}
public async getMetrics(sessionId: any, requestId: any): Promise <any> {
const url = this.config.backendUrl + "/check/metrics";
const options = {
uri: url,
headers: {
"X-IDCHECK-SESSION_ID": sessionId,
},
body: {},
json: true,
resolveWithFullResponse: true,
};
const metrics = await request.get(options);
return metrics;
}
I am calling processMetrics from a different async function. processMetrics is calling a backend (getMetrics) every 2 seconds, it will retry 10 times to see if the result is ready. If it is I will store something in the database and then return.
javascript node.js error-handling http express.js
$endgroup$
I have implemented a simple do/while loop to handle a http request to a third-party. I don’t know when the data I receive will have elements in its array so I retry up to 10 times until the array given to me has data which then I stop and store the data in my database.
My question is in terms of performance is my API going to be affected by having this retry mechanism using a simple do/while loop? If so what is a better way to implement a retry mechanism like this??
public MAX_RETRY = 10;
public async processMetrics(sessionId: any, side: any): Promise <any> {
try {
let metrics;
let retryAttempts = 0;
do {
await new Promise((done) => setTimeout(done, 2000));
metrics = await this.getMetrics(session._id, sessionRequest._id);
retryAttempts++;
} while (!metrics.body.metrics.length && (retryAttempts < this.MAX_RETRY));
// Store in DB
} catch (err) {
}
}
public async getMetrics(sessionId: any, requestId: any): Promise <any> {
const url = this.config.backendUrl + "/check/metrics";
const options = {
uri: url,
headers: {
"X-IDCHECK-SESSION_ID": sessionId,
},
body: {},
json: true,
resolveWithFullResponse: true,
};
const metrics = await request.get(options);
return metrics;
}
I am calling processMetrics from a different async function. processMetrics is calling a backend (getMetrics) every 2 seconds, it will retry 10 times to see if the result is ready. If it is I will store something in the database and then return.
javascript node.js error-handling http express.js
javascript node.js error-handling http express.js
edited Mar 13 at 23:36
200_success
130k17155419
130k17155419
asked Mar 13 at 22:13
user195155user195155
111
111
$begingroup$
So this seems to be within the context of a class. You should include the entire class for review so full context can be seen. Also this appears to be Typescript, so you should ad that to your tags.
$endgroup$
– Mike Brant
Mar 18 at 21:33
add a comment |
$begingroup$
So this seems to be within the context of a class. You should include the entire class for review so full context can be seen. Also this appears to be Typescript, so you should ad that to your tags.
$endgroup$
– Mike Brant
Mar 18 at 21:33
$begingroup$
So this seems to be within the context of a class. You should include the entire class for review so full context can be seen. Also this appears to be Typescript, so you should ad that to your tags.
$endgroup$
– Mike Brant
Mar 18 at 21:33
$begingroup$
So this seems to be within the context of a class. You should include the entire class for review so full context can be seen. Also this appears to be Typescript, so you should ad that to your tags.
$endgroup$
– Mike Brant
Mar 18 at 21:33
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
In terms of performance this should not be an issue, because async operations don't block the event loop, meaning your server will happily accept incoming requests in between the retries. Once in 2 seconds it will be busy making the request to the 3rd party API, but other than that your will not be blocking the main thread.
(You can verify that by shooting requests to your API while it is in the while loop).
New contributor
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215381%2fnode-js-http-retry-do-while-mechanism%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
In terms of performance this should not be an issue, because async operations don't block the event loop, meaning your server will happily accept incoming requests in between the retries. Once in 2 seconds it will be busy making the request to the 3rd party API, but other than that your will not be blocking the main thread.
(You can verify that by shooting requests to your API while it is in the while loop).
New contributor
$endgroup$
add a comment |
$begingroup$
In terms of performance this should not be an issue, because async operations don't block the event loop, meaning your server will happily accept incoming requests in between the retries. Once in 2 seconds it will be busy making the request to the 3rd party API, but other than that your will not be blocking the main thread.
(You can verify that by shooting requests to your API while it is in the while loop).
New contributor
$endgroup$
add a comment |
$begingroup$
In terms of performance this should not be an issue, because async operations don't block the event loop, meaning your server will happily accept incoming requests in between the retries. Once in 2 seconds it will be busy making the request to the 3rd party API, but other than that your will not be blocking the main thread.
(You can verify that by shooting requests to your API while it is in the while loop).
New contributor
$endgroup$
In terms of performance this should not be an issue, because async operations don't block the event loop, meaning your server will happily accept incoming requests in between the retries. Once in 2 seconds it will be busy making the request to the 3rd party API, but other than that your will not be blocking the main thread.
(You can verify that by shooting requests to your API while it is in the while loop).
New contributor
New contributor
answered 55 mins ago
OzWOzW
1011
1011
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215381%2fnode-js-http-retry-do-while-mechanism%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
So this seems to be within the context of a class. You should include the entire class for review so full context can be seen. Also this appears to be Typescript, so you should ad that to your tags.
$endgroup$
– Mike Brant
Mar 18 at 21:33