chore: remove retry dependency in favor of backoff (#15788)

* chore: remove retry dep in favor of backoff

* Fix lint
This commit is contained in:
Beto Dealmeida
2021-07-20 10:33:37 -07:00
committed by GitHub
parent cbd37801a0
commit c9dad05f2b
7 changed files with 53 additions and 13 deletions

38
superset/utils/retries.py Normal file
View File

@@ -0,0 +1,38 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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
#
# http://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.
from typing import Any, Callable, Dict, Generator, List, Optional, Type
import backoff
def retry_call(
func: Callable[..., Any],
*args: Any,
strategy: Callable[..., Generator[int, None, None]] = backoff.constant,
exception: Type[Exception] = Exception,
fargs: Optional[List[Any]] = None,
fkwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
) -> Any:
"""
Retry a given call.
"""
decorated = backoff.on_exception(strategy, exception, *args, **kwargs)(func)
fargs = fargs or []
fkwargs = fkwargs or {}
return decorated(*fargs, **fkwargs)

View File

@@ -20,7 +20,6 @@ from time import sleep
from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING
from flask import current_app
from retry.api import retry_call
from selenium.common.exceptions import (
StaleElementReferenceException,
TimeoutException,
@@ -33,6 +32,7 @@ from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from superset.extensions import machine_auth_provider_factory
from superset.utils.retries import retry_call
WindowSize = Tuple[int, int]
logger = logging.getLogger(__name__)
@@ -85,7 +85,7 @@ class WebDriverProxy:
# This is some very flaky code in selenium. Hence the retries
# and catch-all exceptions
try:
retry_call(driver.close, tries=tries)
retry_call(driver.close, max_tries=tries)
except Exception: # pylint: disable=broad-except
pass
try: