当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.ServiceUnavailable方法代码示例

本文整理汇总了Python中google.api_core.exceptions.ServiceUnavailable方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.ServiceUnavailable方法的具体用法?Python exceptions.ServiceUnavailable怎么用?Python exceptions.ServiceUnavailable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.api_core.exceptions的用法示例。


在下文中一共展示了exceptions.ServiceUnavailable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_grpc_error

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def test_grpc_error(stub):
        api = stub.return_value
        future = tasklets.Future()
        api.foo.future.return_value = future

        class DummyError(grpc.Call, Exception):
            def code(self):
                return grpc.StatusCode.UNAVAILABLE

            def details(self):
                return "Where is the devil in?"

        try:
            raise DummyError("Have to raise in order to get traceback")
        except Exception as error:
            future.set_exception(error)

        request = object()
        with pytest.raises(core_exceptions.ServiceUnavailable):
            _api.make_call("foo", request, retries=0).result() 
开发者ID:googleapis,项目名称:python-ndb,代码行数:22,代码来源:test__datastore_api.py

示例2: tearDown

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def tearDown(self):
        def _still_in_use(bad_request):
            return any(
                error["reason"] == "resourceInUse" for error in bad_request._errors
            )

        retry_in_use = RetryErrors(BadRequest, error_predicate=_still_in_use)
        retry_storage_errors_conflict = RetryErrors(
            (Conflict, TooManyRequests, InternalServerError, ServiceUnavailable)
        )
        for doomed in self.to_delete:
            if isinstance(doomed, storage.Bucket):
                retry_storage_errors_conflict(doomed.delete)(force=True)
            elif isinstance(doomed, (Dataset, bigquery.DatasetReference)):
                retry_in_use(Config.CLIENT.delete_dataset)(doomed, delete_contents=True)
            elif isinstance(doomed, (Table, bigquery.TableReference)):
                retry_in_use(Config.CLIENT.delete_table)(doomed)
            else:
                doomed.delete() 
开发者ID:googleapis,项目名称:python-bigquery,代码行数:21,代码来源:system.py

示例3: _gcs_should_retry_on

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def _gcs_should_retry_on(e):
    # Retry on all 503 errors and 500, as recommended by https://cloud.google.com/apis/design/errors#error_retries
    return isinstance(e, (InternalServerError, ServiceUnavailable, requests.exceptions.ConnectionError)) 
开发者ID:openai,项目名称:lm-human-preferences,代码行数:5,代码来源:gcs.py

示例4: test_w_unavailable

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def test_w_unavailable(self):
        from google.api_core.exceptions import ServiceUnavailable

        exception = ServiceUnavailable("testing")

        self.assertTrue(self._callFUT(exception)) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:8,代码来源:test_watch.py

示例5: test_success_third_attempt

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def test_success_third_attempt(self, _sleep):
        from google.api_core import exceptions
        from google.cloud.firestore_v1.gapic import firestore_client

        # Create a minimal fake GAPIC with a dummy result.
        firestore_api = mock.create_autospec(
            firestore_client.FirestoreClient, instance=True
        )
        # Make sure the first two requests fail and the third succeeds.
        firestore_api.commit.side_effect = [
            exceptions.ServiceUnavailable("Server sleepy."),
            exceptions.ServiceUnavailable("Server groggy."),
            mock.sentinel.commit_response,
        ]

        # Attach the fake GAPIC to a real client.
        client = _make_client("outside")
        client._firestore_api_internal = firestore_api

        # Call function and check result.
        txn_id = b"the-world\x00"
        commit_response = self._call_fut(client, mock.sentinel.write_pbs, txn_id)
        self.assertIs(commit_response, mock.sentinel.commit_response)

        # Verify mocks used.
        self.assertEqual(_sleep.call_count, 2)
        _sleep.assert_any_call(1.0)
        _sleep.assert_any_call(2.0)
        # commit() called same way 3 times.
        commit_call = mock.call(
            client._database_string,
            mock.sentinel.write_pbs,
            transaction=txn_id,
            metadata=client._rpc_metadata,
        )
        self.assertEqual(
            firestore_api.commit.mock_calls, [commit_call, commit_call, commit_call]
        ) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:40,代码来源:test_transaction.py

示例6: test_failure_second_attempt

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def test_failure_second_attempt(self, _sleep):
        from google.api_core import exceptions
        from google.cloud.firestore_v1.gapic import firestore_client

        # Create a minimal fake GAPIC with a dummy result.
        firestore_api = mock.create_autospec(
            firestore_client.FirestoreClient, instance=True
        )
        # Make sure the first request fails retry-able and second
        # fails non-retryable.
        exc1 = exceptions.ServiceUnavailable("Come back next time.")
        exc2 = exceptions.InternalServerError("Server on fritz.")
        firestore_api.commit.side_effect = [exc1, exc2]

        # Attach the fake GAPIC to a real client.
        client = _make_client("peanut-butter")
        client._firestore_api_internal = firestore_api

        # Call function and check result.
        txn_id = b"the-journey-when-and-where-well-go"
        with self.assertRaises(exceptions.InternalServerError) as exc_info:
            self._call_fut(client, mock.sentinel.write_pbs, txn_id)

        self.assertIs(exc_info.exception, exc2)

        # Verify mocks used.
        _sleep.assert_called_once_with(1.0)
        # commit() called same way 2 times.
        commit_call = mock.call(
            client._database_string,
            mock.sentinel.write_pbs,
            transaction=txn_id,
            metadata=client._rpc_metadata,
        )
        self.assertEqual(firestore_api.commit.mock_calls, [commit_call, commit_call]) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:37,代码来源:test_transaction.py

示例7: test_success_third_attempt

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def test_success_third_attempt(self, _sleep):
        from google.api_core import exceptions
        from google.cloud.firestore_v1beta1.gapic import firestore_client

        # Create a minimal fake GAPIC with a dummy result.
        firestore_api = mock.create_autospec(
            firestore_client.FirestoreClient, instance=True
        )
        # Make sure the first two requests fail and the third succeeds.
        firestore_api.commit.side_effect = [
            exceptions.ServiceUnavailable("Server sleepy."),
            exceptions.ServiceUnavailable("Server groggy."),
            mock.sentinel.commit_response,
        ]

        # Attach the fake GAPIC to a real client.
        client = _make_client("outside")
        client._firestore_api_internal = firestore_api

        # Call function and check result.
        txn_id = b"the-world\x00"
        commit_response = self._call_fut(client, mock.sentinel.write_pbs, txn_id)
        self.assertIs(commit_response, mock.sentinel.commit_response)

        # Verify mocks used.
        self.assertEqual(_sleep.call_count, 2)
        _sleep.assert_any_call(1.0)
        _sleep.assert_any_call(2.0)
        # commit() called same way 3 times.
        commit_call = mock.call(
            client._database_string,
            mock.sentinel.write_pbs,
            transaction=txn_id,
            metadata=client._rpc_metadata,
        )
        self.assertEqual(
            firestore_api.commit.mock_calls, [commit_call, commit_call, commit_call]
        ) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:40,代码来源:test_transaction.py

示例8: test_failure_second_attempt

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def test_failure_second_attempt(self, _sleep):
        from google.api_core import exceptions
        from google.cloud.firestore_v1beta1.gapic import firestore_client

        # Create a minimal fake GAPIC with a dummy result.
        firestore_api = mock.create_autospec(
            firestore_client.FirestoreClient, instance=True
        )
        # Make sure the first request fails retry-able and second
        # fails non-retryable.
        exc1 = exceptions.ServiceUnavailable("Come back next time.")
        exc2 = exceptions.InternalServerError("Server on fritz.")
        firestore_api.commit.side_effect = [exc1, exc2]

        # Attach the fake GAPIC to a real client.
        client = _make_client("peanut-butter")
        client._firestore_api_internal = firestore_api

        # Call function and check result.
        txn_id = b"the-journey-when-and-where-well-go"
        with self.assertRaises(exceptions.InternalServerError) as exc_info:
            self._call_fut(client, mock.sentinel.write_pbs, txn_id)

        self.assertIs(exc_info.exception, exc2)

        # Verify mocks used.
        _sleep.assert_called_once_with(1.0)
        # commit() called same way 2 times.
        commit_call = mock.call(
            client._database_string,
            mock.sentinel.write_pbs,
            transaction=txn_id,
            metadata=client._rpc_metadata,
        )
        self.assertEqual(firestore_api.commit.mock_calls, [commit_call, commit_call]) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:37,代码来源:test_transaction.py

示例9: _commit_with_retry

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def _commit_with_retry(client, write_pbs, transaction_id):
    """Call ``Commit`` on the GAPIC client with retry / sleep.

    Retries the ``Commit`` RPC on Unavailable. Usually this RPC-level
    retry is handled by the underlying GAPICd client, but in this case it
    doesn't because ``Commit`` is not always idempotent. But here we know it
    is "idempotent"-like because it has a transaction ID. We also need to do
    our own retry to special-case the ``INVALID_ARGUMENT`` error.

    Args:
        client (~.firestore_v1beta1.client.Client): A client with
            GAPIC client and configuration details.
        write_pbs (List[google.cloud.proto.firestore.v1beta1.\
            write_pb2.Write, ...]): A ``Write`` protobuf instance to
            be committed.
        transaction_id (bytes): ID of an existing transaction that
            this commit will run in.

    Returns:
        google.cloud.firestore_v1beta1.types.CommitResponse:
        The protobuf response from ``Commit``.

    Raises:
        ~google.api_core.exceptions.GoogleAPICallError: If a non-retryable
            exception is encountered.
    """
    current_sleep = _INITIAL_SLEEP
    while True:
        try:
            return client._firestore_api.commit(
                client._database_string,
                write_pbs,
                transaction=transaction_id,
                metadata=client._rpc_metadata,
            )
        except exceptions.ServiceUnavailable:
            # Retry
            pass

        current_sleep = _sleep(current_sleep) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:42,代码来源:transaction.py

示例10: test_unavailable

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def test_unavailable(core_retry):
        error = core_exceptions.ServiceUnavailable("testing")
        core_retry.if_transient_error.return_value = False
        assert _retry.is_transient_error(error) is True
        core_retry.if_transient_error.assert_called_once_with(error) 
开发者ID:googleapis,项目名称:python-ndb,代码行数:7,代码来源:test__retry.py

示例11: test__should_recover_true

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def test__should_recover_true():
    manager = make_manager()

    details = "UNAVAILABLE. Service taking nap."
    exc = exceptions.ServiceUnavailable(details)

    assert manager._should_recover(exc) is True 
开发者ID:googleapis,项目名称:python-pubsub,代码行数:9,代码来源:test_streaming_pull_manager.py

示例12: retry_on_exceptions

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def retry_on_exceptions(exception):
    return isinstance(
        exception, (Aborted, ServiceUnavailable, DeadlineExceeded)) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:5,代码来源:snippets_test.py

示例13: test_create_resumable_upload_session_with_failure

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def test_create_resumable_upload_session_with_failure(self):
        from google.resumable_media import InvalidResponse
        from google.cloud import exceptions

        message = "5-oh-3 woe is me."
        response = self._mock_requests_response(
            status_code=http_client.SERVICE_UNAVAILABLE, headers={}
        )
        side_effect = InvalidResponse(response, message)

        with self.assertRaises(exceptions.ServiceUnavailable) as exc_info:
            self._create_resumable_upload_session_helper(side_effect=side_effect)

        self.assertIn(message, exc_info.exception.message)
        self.assertEqual(exc_info.exception.errors, []) 
开发者ID:googleapis,项目名称:python-storage,代码行数:17,代码来源:test_blob.py

示例14: tearDown

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def tearDown(self):
        errors = (exceptions.TooManyRequests, exceptions.ServiceUnavailable)
        retry = RetryErrors(errors, max_tries=6)
        for blob in self.case_blobs_to_delete:
            retry(blob.delete)() 
开发者ID:googleapis,项目名称:python-storage,代码行数:7,代码来源:test_system.py

示例15: tearDownClass

# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import ServiceUnavailable [as 别名]
def tearDownClass(cls):
        errors = (exceptions.TooManyRequests, exceptions.ServiceUnavailable)
        retry = RetryErrors(errors, max_tries=6)
        for blob in cls.suite_blobs_to_delete:
            retry(blob.delete)() 
开发者ID:googleapis,项目名称:python-storage,代码行数:7,代码来源:test_system.py


注:本文中的google.api_core.exceptions.ServiceUnavailable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。