Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
retry=tenacity.retry_if_exception_type(CustomError))
def _retryable_test_with_exception_type_custom_attempt_limit(thing):
return thing.go()
def test_retry_object(vault_prefix, mocker):
config = Konfig(
vault_backend=VaultBackend(
vault_prefix,
retry=Retrying(retry=retry_if_exception_type(KonfettiError), reraise=True, stop=stop_after_attempt(2)),
)
)
mocker.patch("requests.adapters.HTTPAdapter.send", side_effect=KonfettiError)
m = mocker.patch.object(config.vault_backend, "_call", wraps=config.vault_backend._call)
with pytest.raises(KonfettiError):
config.SECRET
assert m.called is True
assert m.call_count == 2
retry=retry_if_exception_type(PapermillRateLimitException),
stop=stop_after_attempt(self.RATE_LIMIT_RETRIES),
wait=wait_exponential(
multiplier=self.RETRY_MULTIPLIER, min=self.RETRY_DELAY, max=self.RETRY_MAX_DELAY
),
reraise=True,
)
def retry_write():
try:
with self._get_client().open(path, 'w') as f:
return f.write(buf)
except Exception as e:
try:
message = e.message
except AttributeError:
message = "Generic exception {} raised".format(type(e))
if gs_is_retriable(e):
from annexremote import RemoteError
from annexremote import ProtocolError
from pathlib import Path
import logging
import humanfriendly
def NotAFolderError(Exception):
pass
retry_conditions = {
'wait': wait_exponential(multiplier=1, max=10),
'retry': (
retry_if_exception_type(HttpError) |
retry_if_exception_type(ConnectionResetError)
),
'stop': stop_after_attempt(5),
'reraise': True,
}
def send_traceback(f):
@wraps(f)
def wrapper(self, *args, **kwargs):
try:
return f(self, *args, **kwargs)
except:
self._send_version()
for line in traceback.format_exc().splitlines():
self.annex.debug(line)
raise
retry=tenacity.retry_if_exception_type(TimeoutException))
def check_responsiveness(self, url):
self.driver.get(url)
time.sleep(1.0)
body_scroll_width = self.driver.execute_script("return document.body.scrollWidth")
body_client_width = self.driver.execute_script("return document.body.clientWidth")
window_inner_width = self.driver.execute_script("return window.innerWidth")
window_outer_width = self.driver.execute_script("return window.outerWidth")
screen_width = self.driver.execute_script("return screen.width")
device_pixel_ratio = self.driver.execute_script("return window.devicePixelRatio")
return {
"body_scroll_width": int(body_scroll_width),
"body_client_width": int(body_client_width),
"window_inner_width": int(window_inner_width),
"window_outer_width": int(window_outer_width),
"device_pixel_ratio": int(device_pixel_ratio),
@retry(retry=retry_if_exception_type(APIRetryException), stop=stop_after_attempt(10), wait=wait_random(10, 30))
def api_helper(self, user):
"""
Helper function for check_hashes(). Pass over an iterable of the users' keys in __secrets and feed it to this.
:param user: Pass in the username of the user to look up. This should be a key of __secrets we can use to lookup
the users information.
:return: None.
:raises: APIRetryException @ if the request fails for whatever reason.
"""
# Broilerplate the data for the Windows Event Log. Need to do this to redact the NT hashes from the log file.
audit_data = {
"accoutName": user,
"Status": self.__secrets[user].get("Status"),
"Check": {
"LastCheck": None,
"Which": [],
"Compromised": None
retry=tenacity.retry_if_exception_type(exc.EtcdLockException)
)
def function_load_check(self, function_id, version, runtime_id):
"""Check function load and scale the workers if needed.
:return: None if no need to scale up otherwise return the service url
"""
with etcd_util.get_worker_lock(function_id, version) as lock:
if not lock.is_acquired():
raise exc.EtcdLockException(
'Etcd: failed to get worker lock for function %s'
'(version %s).' % (function_id, version)
)
workers = etcd_util.get_workers(function_id, version)
running_execs = db_api.get_executions(
function_id=function_id,
retry=retry_if_exception_type(ResourceStillThereError),
)
def await_no_resources_found(list_resources: Callable, **kwargs):
try:
found = list_resources(**kwargs)
except ApiException as err:
if err.status == STATUS_NOT_FOUND:
return
raise
if hasattr(found, "items"):
found = found.items
if found:
raise ResourceStillThereError(f"Resource(s): {found} still found; retrying.")
def retrying(self):
retry_condition = (
tenacity.retry_if_exception_type(ApiConnectionError)
| tenacity.retry_if_exception_type(ApiInternalServerError)
)
return tenacity.Retrying(
reraise=True,
retry=retry_condition,
stop=tenacity.stop_after_attempt(self.config.RETRIES)
)
retry=(retry_if_exception_type(psycopg2.OperationalError) | retry_if_exception_type(ConnectionError)),
stop=stop_after_delay(120))
def init_db_pool(db_min_connections, db_max_connections):
"""
Initializes the database connection pool required by the application to connect to the database.
"""
db = config.DATABASE
host = config.DATABASE_SERVER
user = config.DATABASE_USER
pw = config.DATABASE_PASSWORD
global connection_pool
if connection_pool is None:
logger.info("Initializing the database connection pool. db: '%s', user: '%s', host: '%s'.", db, user, host)
try:
connection_pool = ThreadedConnectionPool(db_min_connections, db_max_connections, database=db, user=user,
password=pw, host=host)