-
Notifications
You must be signed in to change notification settings - Fork 322
feat: retry failed query jobs in result()
#837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
cc62448
initial stab
61e1c38
test start
093f9b4
Test high-level retry behavior.
b2ce74b
Don't retry here
d930c83
reworked the retry logic.
bf7b4c6
if, when retrying, the new query job is complete and errorer, stop ri…
0598197
Added test (and to existing test) to make sure we can call result mul…
c9644e9
Keep carrying retry_do_query, even though it shouldn't be necessary.
2d0e067
blacken
0dcac01
removed unecessary condition
026edba
System test that demonstrates the retry behavior as applied to the or…
0e764d2
Added missing copyright
c96d8b3
Added missing copyright
5058cb4
Merge branch 'master' into fix-retry
tswast 3c53172
Added a leading _ to the retry_do_query query-jov attribute to make i…
eb51432
Merge branch 'master' into fix-retry
tswast d6d958f
fixed copyright
a05f75f
Merge branch 'fix-retry' of github.com:jimfulton/python-bigquery into…
32e7050
why sleep?
3361a82
use DEFAULT_RETRY for low-level requests, to retry API errors
4c6ef5b
Separate job retry into separate option for client query and query-jo…
25b44a0
Merge branch 'master' into fix-retry
9ab84e4
Use None job_retry to disable retry
d2bf840
Use a 10-minute deadline for job retry by default
4c004a5
Merge branch 'fix-retry' of github.com:jimfulton/python-bigquery into…
be49c4b
Merge branch 'master' into fix-retry
9e4a011
Merge branch 'master' into fix-retry
204641b
Merge branch 'master' into fix-retry
bf051b0
Added another default reason to retry jobs
b47244f
Merge branch 'fix-retry' of github.com:jimfulton/python-bigquery into…
2377a1b
Merge branch 'master' into fix-retry
6b790e8
Update tests/unit/test_job_retry.py
tswast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Copyright 2021 Google LLC | ||
| # | ||
| # Licensed 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 | ||
| # | ||
| # https://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. | ||
|
|
||
| import contextlib | ||
| import threading | ||
| import time | ||
|
|
||
| import google.api_core.exceptions | ||
| import google.cloud.bigquery | ||
| import pytest | ||
|
|
||
|
|
||
| def thread(func): | ||
| thread = threading.Thread(target=func, daemon=True) | ||
| thread.start() | ||
| return thread | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("job_retry_on_query", [True, False]) | ||
| def test_query_retry_539(bigquery_client, dataset_id, job_retry_on_query): | ||
| """ | ||
| Test job_retry | ||
|
|
||
| See: https://github.com/googleapis/python-bigquery/issues/539 | ||
| """ | ||
| from google.api_core import exceptions | ||
| from google.api_core.retry import if_exception_type, Retry | ||
|
|
||
| table_name = f"{dataset_id}.t539" | ||
|
|
||
| # Without a custom retry, we fail: | ||
| with pytest.raises(google.api_core.exceptions.NotFound): | ||
| bigquery_client.query(f"select count(*) from {table_name}").result() | ||
|
|
||
| retry_notfound = Retry(predicate=if_exception_type(exceptions.NotFound)) | ||
|
|
||
| job_retry = dict(job_retry=retry_notfound) if job_retry_on_query else {} | ||
| job = bigquery_client.query(f"select count(*) from {table_name}", **job_retry) | ||
| job_id = job.job_id | ||
|
|
||
| # We can already know that the job failed, but we're not supposed | ||
| # to find out until we call result, which is where retry happend | ||
| assert job.done() | ||
| assert job.exception() is not None | ||
|
|
||
| @thread | ||
| def create_table(): | ||
| time.sleep(1) # Give the first retry attempt time to fail. | ||
| with contextlib.closing(google.cloud.bigquery.Client()) as client: | ||
| client.query(f"create table {table_name} (id int64)").result() | ||
|
|
||
| job_retry = {} if job_retry_on_query else dict(job_retry=retry_notfound) | ||
| [[count]] = list(job.result(**job_retry)) | ||
| assert count == 0 | ||
|
|
||
| # The job was retried, and thus got a new job id | ||
| assert job.job_id != job_id | ||
|
|
||
| # Make sure we don't leave a thread behind: | ||
| create_table.join() | ||
| bigquery_client.query(f"drop table {table_name}").result() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.