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 1 commit
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
38 changes: 26 additions & 12 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,16 +169,28 @@ def show(self, uri):
auth = self.auth
))


def _wait_for_finish(self, is_finished, is_failed, progress, timeout, sleeptime):
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()
progress(self)
if is_failed(self):
raise ResourceFailedException(me)
time.sleep(sleeptime)
return self
def retry(e, attempts):
if attempts < 5:
attempts = attempts + 1
sleep(attempts * attempts * 2)
return wff(time.time(), attempts)
else:
raise e
vickingan marked this conversation as resolved.
Show resolved Hide resolved

def wff(started, attempts):
while not is_finished(self):
current = time.time()
if timeout and (current - started > timeout):
timeoutWarn = "Timed out after %s seconds waiting for completion for %s on attempts %i" % (timeout, str(self), attempts)
log.warn(timeoutWarn)
ex = TimeoutException(timeoutWarn)
retry(e, attempts)
vickingan marked this conversation as resolved.
Show resolved Hide resolved
me = self.show()
vickingan marked this conversation as resolved.
Show resolved Hide resolved
progress(self)
if is_failed(self):
raise ResourceFailedException(me)
time.sleep(sleeptime)
return self

return wff(time.time(), 0)