Skip to content

Commit b2af41b

Browse files
authored
docs(discoveryengine): Add Sample for Cancel Operation (#13330)
* docs(discoveryengine): Add Cancel Operation Sample * Formatting * Update copyright
1 parent 8d57455 commit b2af41b

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
# [START genappbuilder_cancel_operation]
17+
from google.cloud import discoveryengine
18+
from google.longrunning import operations_pb2
19+
20+
# TODO(developer): Uncomment these variables before running the sample.
21+
# Example: `projects/{project}/locations/{location}/collections/{default_collection}/dataStores/{search_engine_id}/branches/{0}/operations/{operation_id}`
22+
# operation_name = "YOUR_OPERATION_NAME"
23+
24+
25+
def cancel_operation_sample(operation_name: str) -> None:
26+
# Create a client
27+
client = discoveryengine.DocumentServiceClient()
28+
29+
# Make CancelOperation request
30+
request = operations_pb2.CancelOperationRequest(name=operation_name)
31+
client.cancel_operation(request=request)
32+
33+
return
34+
35+
36+
# [END genappbuilder_cancel_operation]

discoveryengine/operations_sample_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import os
1717

18+
from discoveryengine import cancel_operation_sample
1819
from discoveryengine import get_operation_sample
1920
from discoveryengine import list_operations_sample
2021
from discoveryengine import poll_operation_sample
@@ -59,3 +60,11 @@ def test_poll_operation():
5960
except NotFound as e:
6061
print(e.message)
6162
pass
63+
64+
65+
def test_cancel_operation():
66+
try:
67+
cancel_operation_sample.cancel_operation_sample(operation_name=operation_name)
68+
except NotFound as e:
69+
print(e.message)
70+
pass

discoveryengine/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
google-cloud-discoveryengine==0.13.4
1+
google-cloud-discoveryengine==0.13.8

0 commit comments

Comments
 (0)