1+ # -*- coding: utf-8 -*-
2+ #
3+ # Copyright 2019 Google LLC
4+ #
5+ # Licensed under the Apache License, Version 2.0 (the "License");
6+ # you may not use this file except in compliance with the License.
7+ # You may obtain a copy of the License at
8+ #
9+ # https://www.apache.org/licenses/LICENSE-2.0
10+ #
11+ # Unless required by applicable law or agreed to in writing, software
12+ # distributed under the License is distributed on an "AS IS" BASIS,
13+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ # See the License for the specific language governing permissions and
15+ # limitations under the License.
16+
17+ import sys
18+
19+ # [START automl_cancel_operation]
20+
21+ from google .cloud import automl_v1beta1
22+
23+
24+ def sample_cancel_operation (project , operation_id ):
25+ """
26+ Cancel Long-Running Operation
27+
28+ Args:
29+ project Required. Your Google Cloud Project ID.
30+ operation_id Required. The ID of the Operation.
31+ """
32+
33+ client = automl_v1beta1 .AutoMlClient ()
34+
35+ operations_client = client .transport ._operations_client
36+
37+ # project = '[Google Cloud Project ID]'
38+ # operation_id = '[Operation ID]'
39+ name = "projects/{}/locations/us-central1/operations/{}" .format (
40+ project , operation_id
41+ )
42+
43+ operations_client .cancel_operation (name )
44+
45+ print (u"Cancelled operation: {}" .format (name ))
46+
47+
48+ # [END automl_cancel_operation]
49+
50+
51+ def main ():
52+ import argparse
53+
54+ parser = argparse .ArgumentParser ()
55+ parser .add_argument ("--project" , type = str , default = "[Google Cloud Project ID]" )
56+ parser .add_argument ("--operation_id" , type = str , default = "[Operation ID]" )
57+ args = parser .parse_args ()
58+
59+ sample_cancel_operation (args .project , args .operation_id )
60+
61+
62+ if __name__ == "__main__" :
63+ main ()
0 commit comments