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

[EN-45543] retry wait for finish #70

Merged
merged 4 commits into from
Apr 15, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions socrata/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import pprint
from socrata.http import noop, get, TimeoutException
import requests
import logging
log = logging.getLogger(__name__)

class Collection(object):
def __init__(self, auth):
Expand Down Expand Up @@ -167,14 +169,29 @@ def show(self, uri):
auth = self.auth
))


def _wait_for_finish(self, is_finished, is_failed, progress, timeout, sleeptime):
started = time.time()
consecutive_failures = 0
last_exception = None
started = time.time();
while not is_finished(self):
current = time.time()
if timeout and (current - started > timeout):
raise TimeoutException("Timed out after %s seconds waiting for completion for %s" % (timeout, str(self)))
me = self.show()
if consecutive_failures > 5 and last_exception is not None:
raise last_exception
try:
me = self.show()
vickingan marked this conversation as resolved.
Show resolved Hide resolved
except RequestException as e:
last_exception = e
consecutive_failures += 1
continue
except UnexpectedResponseException as e:
if 500 <= e.status <= 599:
last_exception = e
consecutive_failures += 1
continue
raise e
vickingan marked this conversation as resolved.
Show resolved Hide resolved
consecutive_failures = 0
progress(self)
if is_failed(self):
raise ResourceFailedException(me)
Expand Down