Skip to content

Commit

Permalink
docs(samples): add tag to statement timeout sample (#2931)
Browse files Browse the repository at this point in the history
* docs(samples): add tag to statement timeout sample

Add a tag to the StatementTimeoutExample, so we can include this sample
in the documentation.

* docs: add clarifying comment regarding setting longer timeout

* chore: reduce line lengths
  • Loading branch information
olavloite committed Mar 7, 2024
1 parent 4905921 commit 2392afe
Showing 1 changed file with 7 additions and 0 deletions.
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]
}

0 comments on commit 2392afe

Please sign in to comment.