Skip to content

Conversation

@bitwiseman
Copy link
Member

@bitwiseman bitwiseman commented Feb 6, 2020

Description

Streamlining and clean up of fetching. Not quite a refactoring but close.
Rate limit changed to be updated for each retry.
Rate and Abuse handlers are part of the retry process - they will not loop indefinitely. They will also be detected without requiring an exception. This means that fetchHttpStatusCode no longer simply returns forbidden status when rate limit is hit.

@bitwiseman bitwiseman marked this pull request as ready for review February 6, 2020 21:38
while (true) {// loop while API rate limit is hit
int responseCode = -1;
String responseMessage = null;

Copy link
Member Author

Choose a reason for hiding this comment

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

It is better to view this in split diff view. Two methods got squashed down and blended.


do {
// if we fail to create a connection we do not retry and we do not wrap
uc = null;
Copy link
Member Author

Choose a reason for hiding this comment

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

This ensures that on retry we don't somehow accidentally use the connection from the previous loop.

// This is where the request is sent and response is processing starts
responseCode = uc.getResponseCode();
responseMessage = uc.getResponseMessage();
noteRateLimit(tailApiUrl);
Copy link
Member Author

Choose a reason for hiding this comment

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

We note the rate limit change as soon as we have confidence that we have enough information to do so.
Better for race conditions.

if (isInvalidCached404Response(responseCode)) {
continue;
}
if (!(isRateLimitResponse(responseCode) || isAbuseLimitResponse(responseCode))) {
Copy link
Member Author

Choose a reason for hiding this comment

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

If we have an error condition that we can detect early, skip calling the lambda.

continue;
}

throw interpretApiError(e, responseCode, responseMessage, url, retries);
Copy link
Member Author

Choose a reason for hiding this comment

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

If the error is not transient, process it if needed and throw.

*/
void handleApiError(IOException e) throws IOException {
int responseCode;
try {
Copy link
Member Author

Choose a reason for hiding this comment

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

This case is handled in the main _fetch method now. We pass in the best known values and don't have to guard against bad state here.


if (!retryConnectionError(e, retries)) {
throw new HttpException(responseCode, responseMessage, uc.getURL(), e);
private void detectOTPRequired(int responseCode) throws GHIOException {
Copy link
Member Author

@bitwiseman bitwiseman Feb 7, 2020

Choose a reason for hiding this comment

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

All of these were move from handleApiError.

Like other errors we've been waiting until later to catch, this one is detectable so
whe should do that before the downstream exception needs to be thrown.
@bitwiseman bitwiseman merged commit 2f32e03 into hub4j:master Feb 13, 2020
@bitwiseman bitwiseman deleted the task/fetch branch February 13, 2020 06:29
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.

1 participant