def retry_call()

in dialogflow-cx/utilities.py [0:0]


def retry_call(api_method, request, max_retries=3, delay=1):
    """Retry an api call multiple times if needed."""
    retry_count = 0
    result = None
    while retry_count < max_retries:
        try:
            result = api_method(request)
            break
        except google.api_core.exceptions.NotFound as exc:
            if str(exc) == (
                "404 com.google.apps.framework.request.NotFoundException: "
                "NLU model for flow '00000000-0000-0000-0000-000000000000' does not exist. "
                "Please try again after retraining the flow."
            ):
                retry_count += 1
                time.sleep(delay)

    if retry_count == max_retries:
        raise RuntimeError("Too many return attempts")

    yield result