當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。