-
Notifications
You must be signed in to change notification settings - Fork 4
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For testing—perhaps mock this.statusFetcher.fetch
to resolve a promise after e.g. 5 seconds, and before that do stopStatusChecks()
and ensure after 5 seconds that the loop is no longer running (by e.g. checking this.statusFetcher.fetch
calls are still 1).
src/EngineEntry.js
Outdated
let health; | ||
let metrics; | ||
|
||
if (!this.running) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have this check on line 74 instead (e.g. only do another setTimeout if we are still running)—for clarity's sake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I agree 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can move it, but be advised, it will lead to unnecessary health/metrics checks if cancellation is made in between status checks (which should be the normal scenario when we don't have recurring engine crashes).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 One comment on a convention.
src/EngineEntry.js
Outdated
@@ -70,18 +44,49 @@ class EngineEntry { | |||
} | |||
|
|||
/** | |||
* Periodical health and metrics checking. | |||
*/ | |||
async checkStatus() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we moving away from the convention to have "private" methods not part of the class definition?
If so, we should align all code with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that's the reason!
Me and @peol discussed this and I did not know the reason for having it outside the class. Anyway, one argument for having it part of the class is to avoid having to use bind()
which creates a new copy of the function every time it's called if I'm correctly informed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with putting them in the class def, but we should align.
Also, it would be very nice if we had some convention for naming "private" methods. I have seen _
suffix but our lint rules does not allow that, I think.
src/EngineEntry.js
Outdated
let health; | ||
let metrics; | ||
|
||
if (!this.running) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I agree 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Only one comment
*/ | ||
async function checkStatus() { | ||
let health; | ||
let metrics; | ||
|
||
if (!this.running) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - I know this is a matter of personal taste but I don't like early exits like this unless it is failure conditions.
I think is better to invert the logic and have if (this.running) {
and then the code we want to run, avoiding multiple exit points if possible. Do as you please 🙂
If a status check was canceled while it was running, it actually cancelled an old timeout identifier which in turn caused status check to go rouge (they continued forever, consuming memory in each iteration).
Any ideas of how to test this in a controlled environment is highly appreciated!