Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add default timeout for Client.get_job()#1935

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Linchin merged 24 commits intogoogleapis:mainfromLinchin:timeout
May 31, 2024

Conversation

@Linchin
Copy link
Contributor

@LinchinLinchin commentedMay 29, 2024
edited
Loading

When callingQueryJob.result(),QueryJob.reload() is called in the background with an empty timeout value. This leadsQueryJob to waiting indefinitely ifQueryJob.reload() loses connection.

This PR:

  • ReroutesQueryJob.reload() to callClient.get_job() instead of calling API directly
  • Adds a 128s default timeout forClient.get_job()

Fixes#1922 🦕

@LinchinLinchin requested review froma team ascode ownersMay 29, 2024 01:49
@LinchinLinchin requested a review fromleahecoleMay 29, 2024 01:49
@product-auto-labelproduct-auto-labelbot added size: lPull request size is large. api: bigqueryIssues related to the googleapis/python-bigquery API. labelsMay 29, 2024
@LinchinLinchin requested review fromtswast and removed request forleahecoleMay 29, 2024 01:50
Copy link
Contributor

@tswasttswast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please add some tests where*Job.reload(timeout=None),*Job.done(timeout=None), and*Job.result(timeout=None) disable the timeouts forjobs.get.

extra_params["location"]=self.location
span_attributes= {"path":self.path}
kwargs:Dict[str,Any]= {}
iftype(timeout)isobject:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Let's add some comments explaining why we need to omit the timeout if we get_DEFAULT_VALUE. (Because we want to use the default API-level timeouts but wait indefinitely for the job to finish)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I added explanation whykwargs is used here, but I feel likeQueryjob.result() is a better place to explain the default timeout behavior, so I added it in docstring there instead.

self,
retry:"retries.Retry"=DEFAULT_RETRY,
timeout:Optional[float]=None,
timeout:Optional[Union[float,object]]=PollingFuture._DEFAULT_VALUE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done isn't waiting for the job to complete, so I wonder if we actually needPollingFuture._DEFAULT_VALUE here?

It seems more analogous toClient.get_job so maybe we can use the sameDEFAULT_GET_JOB_TIMEOUT, here? 🤔 We need to double-check that we aren't calling any other API requests like getQueryResults, if so.

Copy link
ContributorAuthor

@LinchinLinchinMay 30, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

done() callsreload(), which in turn callsClient.get_job(). So I added the sentinel values along the pathresult() ->done() ->reload(). Indeed I realize we don't have to add sentinel fordone() orreload(), because it will be passed fromresult() anyway. As to getQueryResults, I don't think it's called fromdone() onward (it's used inresult()). I think either way (usingPollingFuture._DEFAULT_VALUE orDEFAULT_GET_JOB_TIMEOUT) it's effectively the same, so I think either way it's fine. Are there any other factors I'm not aware of?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'd like to keep our type annotations as narrow as we can. My worry withPollingFuture._DEFAULT_VALUE is it opens it up toobject, which technically is anything (string, bytes, anything) in Python.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Indeed, I ended up only using sentinel forresult(), and usedDEFAULT_GET_JOB_TIMEOUT for subsequent calls.

Comment on lines 1518 to 1522
iftype(timeout)isobject:
timeout=None
get_job_timeout=PollingFuture._DEFAULT_VALUE
else:
get_job_timeout=timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why not do the kwargs trick here too?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I wonder if it's necessary - the purpose here is slightly different from when callingclient.get_job(). I'm only preserving the sentinel value for thejob.done() call, and use None as default for any other calls.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

done, following later comments

client=None,
retry:"retries.Retry"=DEFAULT_RETRY,
timeout:Optional[float]=None,
timeout:Optional[Union[float,object]]=POLLING_DEFAULT_VALUE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'd much rather this defaulted to the same timeout asget_job() and anywhere that callsreload(), we make sure we do the check forPOLLING_DEFAULT_VALUE before callingreload() to make sure we only pass infloat orNone or omit the value.

Linchin reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

done

self,
retry:"retries.Retry"=DEFAULT_RETRY,
timeout:Optional[float]=None,
timeout:Optional[Union[float,object]]=POLLING_DEFAULT_VALUE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Same here. I don't think this needs to handlePOLLING_DEFAULT_VALUE since it's not waiting for the job to finish, just making at most 1 API call.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

done

# timeout to QueryJob.done(), and use None for the other timeouts.
iftype(timeout)isobject:
timeout=None
get_job_timeout=POLLING_DEFAULT_VALUE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why not set toDEFAULT_GET_JOB_TIMEOUT or do the kwargs trick to omit it?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

done

Linchinand others added5 commitsMay 31, 2024 13:23
Co-authored-by: Tim Sweña (Swast) <swast@google.com>
Co-authored-by: Tim Sweña (Swast) <swast@google.com>
Copy link
Contributor

@tswasttswast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Love it! Just a couple of typos to fix please before merging

Linchin reacted with heart emoji
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@tswasttswasttswast approved these changes

Assignees

@tswasttswast

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.size: lPull request size is large.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

QueryJob.result() not identifying and returning after submitted query completes

2 participants

@Linchin@tswast

[8]ページ先頭

©2009-2025 Movatter.jp