iwonbigbro / gsync

RSync for Google Drive - GSync
Other
238 stars 50 forks source link

Implement retries aka fix BadStatusLine exceptions. #48

Open quadrater opened 10 years ago

quadrater commented 10 years ago

Seems like Google and/or httplib has issues in the communication from time to time and raises BadStatusLine exceptions. For this purpuse a general retry would be nice and I did a quick and probably naive implementation as per below. It does not take care of any internal states needed to be cleaned up in src or dst objects.

In libgsync/sync/__init__.py:

        max_retries = 3
        for retry in range(max_retries):
            try:
                if create:
                    self.dst.create(dstPath, srcFile)

                elif GsyncOptions.ignore_existing:
                    debug("File exists on the receiver, skipping: %s" % (
                        repr(path)
                    ))
                    return None

                elif update:
                    self.dst.update(dstPath, srcFile)

            except KeyboardInterrupt, e:
                debug("Interrupted")
                raise
            except:
                debug("Sync try %s of %s failed." % (retry + 1, max_retries))
                continue
            finally:
                self.totalBytesSent += self.dst.bytesWritten
                self.totalBytesReceived += self.dst.bytesRead
            break
iwonbigbro commented 10 years ago

Good suggestion. I will see about implementing this in the next week or so. I need to create a test for it, so I will need to create some mock interfaces to guarantee failures occur.

iwonbigbro commented 10 years ago

Duplicate #43