GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — feast/sdk/python/feast/wait.py at master · iamcodingcat/feast Expand file tree/ Copy pathwait.pyMore file actions 55 lines (49 loc) · 2.23 KB / Copy pathwait.pyFile metadata and controls55 lines (49 loc) · 2.23 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 # Copyright 2019 The Feast Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import time from typing import Any, Callable, Optional, Tuple from feast.constants import MAX_WAIT_INTERVAL def wait_retry_backoff( retry_fn: Callable[[], Tuple[Any, bool]], timeout_secs: int = 0, timeout_msg: Optional[str] = "Timeout while waiting for retry_fn() to return True", max_interval_secs: int = int(MAX_WAIT_INTERVAL), ) -> Any: """ Repeatedly try calling given retry_fn until it returns a True boolean success flag. Waits with a exponential backoff between retries until timeout when it throws TimeoutError. Args: retry_fn: Callable that returns a result and a boolean success flag. timeout_secs: timeout in seconds to give up retrying and throw TimeoutError, or 0 to retry perpetually. timeout_msg: Message to use when throwing TimeoutError. max_interval_secs: max wait in seconds to wait between retries. Returns: Returned Result from retry_fn() if success flag is True. """ wait_secs, elapsed_secs = 1.0, 0.0 result, is_success = retry_fn() wait_begin = time.time() while not is_success and (elapsed_secs <= timeout_secs or timeout_secs == 0): # back off wait duration exponentially, capped at MAX_WAIT_INTERVAL_SEC elapsed_secs = time.time() - wait_begin till_timeout_secs = timeout_secs - elapsed_secs wait_secs = min(wait_secs * 2, max_interval_secs, till_timeout_secs) time.sleep(wait_secs) # retry call result, is_success = retry_fn() elapsed_secs = time.time() - wait_begin if not is_success and elapsed_secs > timeout_secs: raise TimeoutError(timeout_msg) return result |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |