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


Python backoff.on_exception方法代码示例

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


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

示例1: publish

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def publish(client, body, topic):
    """Publish a message to a Pub/Sub topic."""
    project = 'projects/{}'.format(utils.get_project_id())
    dest_topic = project + '/topics/' + topic

    @backoff.on_exception(
        backoff.expo, HttpError, max_tries=3, giveup=utils.fatal_code)
    def _do_request():
        client.projects().topics().publish(
            topic=dest_topic, body=body).execute()

    try:
        _do_request()
    except HttpError as e:
        logging.error(e)
        raise PubSubException(e) 
开发者ID:doitintl,项目名称:iris,代码行数:18,代码来源:pubsub.py

示例2: pull

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def pull(client, sub, endpoint):
    """Register a listener endpoint."""
    subscription = get_full_subscription_name(utils.get_project_id(), sub)
    body = {'pushConfig': {'pushEndpoint': endpoint}}

    @backoff.on_exception(
        backoff.expo, HttpError, max_tries=3, giveup=utils.fatal_code)
    def _do_request():
        client.projects().subscriptions().modifyPushConfig(
            subscription=subscription, body=body).execute()

    try:
        _do_request()
    except HttpError as e:

        logging.error(e)
        return 'Error', 500
    return 'ok, 204' 
开发者ID:doitintl,项目名称:iris,代码行数:20,代码来源:pubsub.py

示例3: test_update_uptime_config

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def test_update_uptime_config(capsys):
    # create and delete happen in uptime fixture.
    new_display_name = random_name(10)
    new_uptime_check_path = '/' + random_name(10)
    with UptimeFixture() as fixture:

        # We sometimes see the permission error saying the resource
        # may not exist. Weirdly DeadlineExceeded instnace is raised
        # in this case.
        @backoff.on_exception(backoff.expo, DeadlineExceeded, max_time=120)
        def call_sample():
            snippets.update_uptime_check_config(
                fixture.config.name, new_display_name, new_uptime_check_path)

        call_sample()

        out, _ = capsys.readouterr()
        snippets.get_uptime_check_config(fixture.config.name)
        out, _ = capsys.readouterr()
        assert new_display_name in out
        assert new_uptime_check_path in out 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:23,代码来源:snippets_test.py

示例4: glossary

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def glossary():
    """Get the ID of a glossary available to session (do not mutate/delete)."""
    glossary_id = "test-{}".format(uuid.uuid4())
    translate_v3_create_glossary.create_glossary(
        PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
    )

    yield glossary_id

    # cleanup
    @backoff.on_exception(
        backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
    )
    def delete_glossary():
        try:
            translate_v3_delete_glossary.delete_glossary(
                PROJECT_ID, glossary_id)
        except NotFound as e:
            # Ignoring this case.
            print("Got NotFound, detail: {}".format(str(e)))
    delete_glossary() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:23,代码来源:translate_v3_batch_translate_text_with_glossary_test.py

示例5: glossary

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def glossary():
    """Get the ID of a glossary available to session (do not mutate/delete)."""
    glossary_id = "must-start-with-letters-" + str(uuid.uuid1())
    translate_v3_create_glossary.create_glossary(
        PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
    )

    yield glossary_id

    # clean up
    @backoff.on_exception(
        backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
    )
    def delete_glossary():
        try:
            translate_v3_delete_glossary.delete_glossary(
                PROJECT_ID, glossary_id)
        except NotFound as e:
            # Ignoring this case.
            print("Got NotFound, detail: {}".format(str(e)))
    delete_glossary() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:23,代码来源:translate_v3_list_glossary_test.py

示例6: glossary

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def glossary():
    """Get the ID of a glossary available to session (do not mutate/delete)."""
    glossary_id = "must-start-with-letters-" + str(uuid.uuid1())
    translate_v3_create_glossary.create_glossary(
        PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
    )

    yield glossary_id

    # cleanup
    @backoff.on_exception(
        backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
    )
    def delete_glossary():
        try:
            translate_v3_delete_glossary.delete_glossary(
                PROJECT_ID, glossary_id)
        except NotFound as e:
            # Ignoring this case.
            print("Got NotFound, detail: {}".format(str(e)))
    delete_glossary() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:23,代码来源:translate_v3_get_glossary_test.py

示例7: test_create_glossary

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def test_create_glossary(capsys):
    try:
        glossary_id = "test-{}".format(uuid.uuid4())
        translate_v3_create_glossary.create_glossary(
            PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
        )
        out, _ = capsys.readouterr()
        # assert
        assert "Created:" in out
        assert "gs://cloud-samples-data/translation/glossary_ja.csv" in out
    finally:
        # cleanup
        @backoff.on_exception(
            backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
        )
        def delete_glossary():
            try:
                translate_v3_delete_glossary.delete_glossary(
                    PROJECT_ID, glossary_id)
            except NotFound as e:
                # Ignoring this case.
                print("Got NotFound, detail: {}".format(str(e)))
        delete_glossary() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:25,代码来源:translate_v3_create_glossary_test.py

示例8: test_label_video

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def test_label_video(
        capsys, annotation_spec_set, instruction, dataset, cleaner):

    @backoff.on_exception(
        backoff.expo, ServerError, max_time=testing_lib.RETRY_DEADLINE)
    def run_sample():
        # Start labeling.
        return label_video.label_video(
            dataset.name, instruction.name, annotation_spec_set.name)

    response = run_sample()
    cleaner.append(response.operation.name)

    out, _ = capsys.readouterr()
    assert 'Label_video operation name: ' in out

    # Cancels the labeling operation.
    response.cancel()
    assert response.cancelled() is True 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:21,代码来源:label_video_test.py

示例9: test_label_text

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def test_label_text(capsys, annotation_spec_set, instruction, dataset, cleaner):

    @backoff.on_exception(
        backoff.expo, ServerError, max_time=testing_lib.RETRY_DEADLINE)
    def run_sample():
        # Start labeling.
        return label_text.label_text(
            dataset.name, instruction.name, annotation_spec_set.name)

    response = run_sample()
    cleaner.append(response.operation.name)

    out, _ = capsys.readouterr()
    assert 'Label_text operation name: ' in out

    # Cancels the labeling operation.
    response.cancel()
    assert response.cancelled() is True 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:20,代码来源:label_text_test.py

示例10: crud_fhir_store_id

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def crud_fhir_store_id():
    yield fhir_store_id

    # Clean up
    @backoff.on_exception(backoff.expo, HttpError, max_time=60)
    def clean_up():
        try:
            fhir_stores.delete_fhir_store(
                project_id, cloud_region, dataset_id, fhir_store_id
            )
        except HttpError as err:
            # The API returns 404 when the FHIR store doesn't exist.
            # The API returns 403 when the dataset doesn't exist, so
            # if we try to delete a FHIR store when the parent dataset
            # doesn't exist, the server will return a 403.
            if err.resp.status == 404 or err.resp.status == 403:
                print(
                    "Got exception {} while deleting FHIR store".format(err.resp.status)
                )
            else:
                raise

    clean_up() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:25,代码来源:fhir_stores_test.py

示例11: crud_dicom_store_id

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def crud_dicom_store_id():
    yield dicom_store_id

    # Clean up
    @backoff.on_exception(backoff.expo, HttpError, max_time=60)
    def clean_up():
        try:
            dicom_stores.delete_dicom_store(
                project_id, cloud_region, dataset_id, dicom_store_id
            )
        except HttpError as err:
            # The API returns 404 when the DICOM store doesn't exist.
            # The API returns 403 when the dataset doesn't exist, so
            # if we try to delete a DICOM store when the parent dataset
            # doesn't exist, the server will return a 403.
            if err.resp.status == 404 or err.resp.status == 403:
                print(
                    "Got exception {} while deleting DICOM store".format(
                        err.resp.status
                    )
                )
            else:
                raise

    clean_up() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:27,代码来源:dicom_stores_test.py

示例12: crud_hl7v2_store_id

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def crud_hl7v2_store_id():
    yield hl7v2_store_id

    # Clean up
    @backoff.on_exception(backoff.expo, HttpError, max_time=60)
    def clean_up():
        try:
            hl7v2_stores.delete_hl7v2_store(
                project_id, cloud_region, dataset_id, hl7v2_store_id
            )
        except HttpError as err:
            # The API returns 403 when the HL7v2 store doesn't exist.
            if err.resp.status == 404 or err.resp.status == 403:
                print(
                    "Got exception {} while deleting HL7v2 store".format(
                        err.resp.status
                    )
                )
            else:
                raise

    clean_up() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:24,代码来源:hl7v2_stores_test.py

示例13: test_auto_complete_sample

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def test_auto_complete_sample(company_name, capsys):
    @backoff.on_exception(backoff.expo, AssertionError, max_time=120)
    def eventually_consistent_test():
        auto_complete_sample.run_sample(company_name)
        out, _ = capsys.readouterr()
        expected = (
            '.*completionResults.*'
            'suggestion.*Google.*type.*COMPANY_NAME.*\n'
            '.*completionResults.*'
            'suggestion.*Software Engineer.*type.*JOB_TITLE.*\n'
            '.*completionResults.*'
            'suggestion.*Software Engineer.*type.*JOB_TITLE.*\n'
        )
        assert re.search(expected, out)

    eventually_consistent_test() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:18,代码来源:auto_complete_sample_test.py

示例14: test_location_search_sample

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def test_location_search_sample(company_name, capsys):
    @backoff.on_exception(backoff.expo, AssertionError, max_time=120)
    def eventually_consistent_test():
        location_search_sample.run_sample(company_name)
        out, _ = capsys.readouterr()
        expected = ('.*locationFilters.*\n'
                    '.*locationFilters.*\n'
                    '.*locationFilters.*\n'
                    '.*locationFilters.*\n'
                    '.*locationFilters.*\n')
        assert re.search(expected, out, re.DOTALL)
        expected = ('.*matchingJobs.*\n'
                    '.*matchingJobs.*\n'
                    '.*matchingJobs.*\n'
                    '.*matchingJobs.*\n'
                    '.*matchingJobs.*\n')
        assert re.search(expected, out, re.DOTALL)

    eventually_consistent_test() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:21,代码来源:location_search_sample_test.py

示例15: test_search_all_resources

# 需要导入模块: import backoff [as 别名]
# 或者: from backoff import on_exception [as 别名]
def test_search_all_resources(asset_dataset, capsys):
    scope = "projects/{}".format(PROJECT)
    query = "name:{}".format(DATASET)

    # Dataset creation takes some time to propagate, so the dataset is not
    # immediately searchable. Need some time before the snippet will pass.
    @backoff.on_exception(
        backoff.expo, (AssertionError), max_time=120
    )
    def eventually_consistent_test():
        quickstart_searchallresources.search_all_resources(scope, query=query)
        out, _ = capsys.readouterr()

        assert DATASET in out

    eventually_consistent_test() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:18,代码来源:quickstart_searchallresources_test.py


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