Skip to content
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

docs(samples): add tag to statement timeout sample #2931

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

class StatementTimeoutExample {

// [START spanner_set_statement_timeout]

static void executeSqlWithTimeout() {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project";
Expand All @@ -52,6 +54,10 @@ public <ReqT, RespT> ApiCallContext configure(ApiCallContext context, ReqT reque
MethodDescriptor<ReqT, RespT> method) {
// DML uses the ExecuteSql RPC.
if (method == SpannerGrpc.getExecuteSqlMethod()) {
// NOTE: You can use a GrpcCallContext to set a custom timeout for a single RPC
// invocation. This timeout can however ONLY BE SHORTER than the default timeout
// for the RPC. If you set a timeout that is longer than the default timeout, then
// the default timeout will be used.
return GrpcCallContext.createDefault()
.withCallOptions(CallOptions.DEFAULT.withDeadlineAfter(60L, TimeUnit.SECONDS));
}
Expand All @@ -73,4 +79,5 @@ public <ReqT, RespT> ApiCallContext configure(ApiCallContext context, ReqT reque
})
);
}
// [END spanner_set_statement_timeout]
}