Skip to content
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

Retry on timeout and 500+ errors #151

Closed
wants to merge 6 commits into from
Closed

Conversation

pypingou
Copy link
Member

This pull-request allows the client to ask for a request to be retried if that request failed due to a
time-out or because it returned an error code >= 500.
In addition, it allows the clients to specify how long they want to wait in between two attempts of
sending the request (defaults to 0.5 second).

Fixes #144

@ralphbean
Copy link
Contributor

What kind of testing have you subjected this to?

@pypingou
Copy link
Member Author

Not much indeed, still planning to but indeed forgot to mention it, sorry :-(

@ralphbean
Copy link
Contributor

Cool. the code looks fine from a read-through, but let's test the tar out of it before we merge it.

If you want to try, there is a bodhi api client test tool in the bodhi repo you could mess with.

@pypingou
Copy link
Member Author

I was thinking to test pkgdb-cli with these changes as well (and eventually to port pkgdb-cli to it)

@@ -182,7 +183,8 @@ def _authed_get(self, url, params=None, data=None, **kwargs):
response = self._session.get(url, params=params, data=data, **kwargs)
return response

def send_request(self, method, auth=False, verb='POST', **kwargs):
def send_request(self, method, auth=False, verb='POST', retries=None,
retry_sleep=0.5, **kwargs):
Copy link

Choose a reason for hiding this comment

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

Would it make sense to put retry_sleep as an attribute of OpenIdBaseClient, similarly to retries? One could then easily create Bodhi2Client and set Bodhi2Client.retry_sleep in order to modify the sleep interval.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. That makes a lot of sense to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done :)

Copy link

Choose a reason for hiding this comment

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

OK, so now you should kick it out of the send_request() parameters and use self.retry_sleep inside it instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

On Wed, Sep 30, 2015 at 08:40:49AM -0700, Kamil Páral wrote:

In fedora/client/openidbaseclient.py:

@@ -182,7 +183,8 @@ def _authed_get(self, url, params=None, data=None, *_kwargs):
response = self._session.get(url, params=params, data=data, *_kwargs)
return response

  • def send_request(self, method, auth=False, verb='POST', **kwargs):
  • def send_request(self, method, auth=False, verb='POST', retries=None,
  •                 retry_sleep=0.5, **kwargs):
    

OK, so now you should kick it out of the send_request() parameters and use
self.retry_sleep inside it instead.

Retries is present in both place on the old client, why not keep it here as
well?

Copy link

Choose a reason for hiding this comment

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

Maybe I'm mistaken, but how can I currently configure retry_sleep? If I do bodhi = Bodhi2Client(); bodhi.retry_sleep = 2, it seems it won't have any effect in send_request() (because you don't utilize the class attribute).

Possible solutions that I see:

  1. Remove retry_sleep from send_request() parameters. Use self.retry_sleep inside the method body.
  2. Use send_request(retry_sleep=None) as a default value, and then have retry_sleep = retry_sleep if retry_sleep is not None or self.retry_sleep (or use multiple lines if you don't like ternary operator) inside the method body.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I was realizing the same after I replied, I'll adjust using 2)

if timeout is None:
timeout = self.timeout

retry_sleep = retry_sleep or self.retry_sleep
Copy link

Choose a reason for hiding this comment

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

There is one slight problem with this, send_request(retry_sleep=0) won't work correctly. You have to compare with None directly.

# 'utf-8'. We can make that assumption because we're only
# interfacing with servers that we run (and we know that they
# all return responses encoded 'utf-8').
response.encoding = 'utf-8'
Copy link
Contributor

Choose a reason for hiding this comment

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

response is undefined here.

@ralphbean
Copy link
Contributor

Hey, this doesn't work at all. I went to test it but there are all kinds of undefined variables that get used in there.

It was a copy/paste from somewhere else? Let's start over. I'm going to close it to get it out of the review queue.

@ralphbean ralphbean closed this Oct 7, 2015
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.

None yet

3 participants