Mercurial > repos > guerler > springsuite
diff planemo/lib/python3.7/site-packages/galaxy/tool_util/verify/wait.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/planemo/lib/python3.7/site-packages/galaxy/tool_util/verify/wait.py Fri Jul 31 00:32:28 2020 -0400 @@ -0,0 +1,28 @@ +"""Abstraction for waiting on API conditions to become true.""" + +import time + + +def wait_on(function, desc, timeout): + """Wait for function to return non-None value.""" + delta = .25 + iteration = 0 + while True: + total_wait = delta * iteration + if total_wait > timeout: + timeout_message = "Timed out after %s seconds waiting on %s." % ( + total_wait, desc + ) + raise TimeoutAssertionError(timeout_message) + iteration += 1 + value = function() + if value is not None: + return value + time.sleep(delta) + + +class TimeoutAssertionError(AssertionError): + """Derivative of AssertionError indicating wait_on exceeded max time.""" + + def __init__(self, message): + super(TimeoutAssertionError, self).__init__(message)