resumable_upload_handler_4.py 1.3 KB

123456789101112131415161718192021222324252627
  1. def track_progress_less_iterations(self, server_had_bytes_before_attempt,
  2. roll_back_md5=True, debug=0):
  3. # At this point we had a re-tryable failure; see if made progress.
  4. if self.server_has_bytes > server_had_bytes_before_attempt:
  5. self.progress_less_iterations = 0 # If progress, reset counter.
  6. else:
  7. self.progress_less_iterations += 1
  8. if roll_back_md5:
  9. # Rollback any potential hash updates, as we did not
  10. # make any progress in this iteration.
  11. self.digesters = self.digesters_before_attempt
  12. if self.progress_less_iterations > self.num_retries:
  13. # Don't retry any longer in the current process.
  14. raise ResumableUploadException(
  15. 'Too many resumable upload attempts failed without '
  16. 'progress. You might try this upload again later',
  17. ResumableTransferDisposition.ABORT_CUR_PROCESS)
  18. # Use binary exponential backoff to desynchronize client requests.
  19. sleep_time_secs = random.random() * (2**self.progress_less_iterations)
  20. if debug >= 1:
  21. print('Got retryable failure (%d progress-less in a row).\n'
  22. 'Sleeping %3.1f seconds before re-trying' %
  23. (self.progress_less_iterations, sleep_time_secs))
  24. time.sleep(sleep_time_secs)