manishdwibedy / solrpy

Automatically exported from code.google.com/p/solrpy
0 stars 0 forks source link

Retry post if badstatusline received #2

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
in the post method, we added retries due to badstatusline:

        attempts = 4
        while attempts: 
            caught_exception = False
            try:
                self.conn.request('POST', url, body.encode('utf-8'), headers)
                return check_response_status(self.conn.getresponse())
            except (socket.error,
                    httplib.ImproperConnectionState,
                    httplib.BadStatusLine):
                    # We include BadStatusLine as they are spurious
                    # and may randomly happen on an otherwise fine 
                    # SOLR connection (though not often)
                time.sleep(1)
                caught_exception = True
            except SolrHTTPException:
                msg = "HTTP error. %s tries left; retrying...\n" % attempts
                sys.stderr.write(msg)
                time.sleep(20)
                caught_exception = True
            if caught_exception:    
                self._reconnect()
                attempts -= 1
                if not attempts:
                    raise

Original issue reported on code.google.com by br...@echonest.com on 24 Mar 2008 at 4:16

GoogleCodeExporter commented 8 years ago
httplib.BadStatusLine exceptions were being handled since r1, although it seems 
it won't hurt if SolrConnection gets additional 'attempts' attribute 
(currently hardcoded to 1). Will it suffice?

I can't comment on the SolrHTTPException/time.sleep part as there's no such
exception in solrpy. Can you please explain what does it do in your code?
How can it raised from the code above?

Original comment by ds...@gefira.pl on 12 Sep 2008 at 9:38

GoogleCodeExporter commented 8 years ago
I've added code for customizing the number of retries. The init method takes a 
named
argument, max_retries. The maximum number of tries is max_retries + 1. If you 
only
want a single attempt, set max_retries to 0. The default has been set to 3 and 
should
be a transparent change.

Changes committed in revision 48 to the trunk.

Original comment by benliles on 12 Oct 2009 at 10:29

GoogleCodeExporter commented 8 years ago

Original comment by benliles on 3 Dec 2009 at 9:05