File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed
Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 1+ # Copyright 2023 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]
Original file line number Diff line number Diff line change 1818from discoveryengine import get_operation_sample
1919from discoveryengine import list_operations_sample
2020from discoveryengine import poll_operation_sample
21+ from discoveryengine import cancel_operation_sample
2122
2223from google .api_core .exceptions import NotFound
2324
@@ -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
Original file line number Diff line number Diff line change 1- google-cloud-discoveryengine == 0.13.4
1+ google-cloud-discoveryengine == 0.13.8
You can’t perform that action at this time.
0 commit comments