-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Fault tolerance #413
Fault tolerance #413
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.
left some comments! please feel free to message me on slack or respond on here if you have any questions
src/services/NetworkService.js
Outdated
["get", "delete", "head", "jsonp"].indexOf(method) !== -1 | ||
? http[method](url, { | ||
timeout: FAULT_TOLERANT_HTTP_TIMEOUT | ||
}).then(this._successHandler, this._errorHandler) |
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 would generally not handle promise returns and errors nested inside like this (as it can be difficult to follow for future programmers). instead, you could handle this promise outside like:
retryHttp: function() {
return promiseRetry(retry => {
...
}, {
retries: FAULT_TOLERANT_HTTP_MAX_RETRIES,
maxTimeout: FAULT_TOLERANT_HTTP_MAX_RETRY_TIMEOUT
})
.then(this._successHandler, this._errorHandler)
.catch(res => {
if (res.status === 0) { ... }
...
});
}
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.
The catch
handler needs to be nested inside the function that is passed to promiseRetry
because it needs to call the passed-in retry
function to signal to promiseRetry
that the function needs to be retried.
I think I'm going to use a different package for managing the retries and backoffs and rewrite this whole chunk of code--the promiseRetry
module looked tempting but as I started implementing the things I needed to implement here (like stopping the requests when the user clicks "Abort") my solutions became increasingly ugly.
src/services/NetworkService.js
Outdated
} | ||
); | ||
} | ||
}.retryHttp(); |
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 you creating the retryHttp method and then calling it immediately? unless im readying the brackets wrong, youre doing something like:
return {
isAborted: false,
retryHttp: function() { ... },
}.retryHttp();
so why not just directly call whatever retryHttp
is doing instead of defining it and then calling it?
also, if you want to, we can pair on some of this stuff as i dont know i conveyed myself super clearly and its confusing |
* no longer need to join session every time we reconnect
also, don't put network or user abort errors on Sentry
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.
looks great! thanks for the changes
this.joinSession(this.session._id); | ||
} else { | ||
location.reload(); | ||
} |
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.
a way to avoid the crazy if statement could be:
if (this.session && this.session._id) {
if (this.session.student && this.session.student._id === this.user._id) return location.reload();
if (this.session.volunteer && this.session.volunteer._id === this.user.Id) return location.reload();
return this.joinSession(this.session._id);
}
i think this looks more readable, but up to you whether you want to change or not
@@ -174,9 +172,6 @@ export default { | |||
}, | |||
sockets: { | |||
"session-change"(sessionData) { | |||
SessionService.currentSession.sessionId = sessionData._id; | |||
SessionService.currentSession.data = sessionData; |
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.
awesome to get rid of this :)
# Conflicts: # src/views/SessionView/index.vue
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.
great work @dmnisson!
Links
Description
promise-retry
SessionService.currentSession
Developer self-review checklist