Navigation Menu

Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
docs: add cancel operation sample
Browse files Browse the repository at this point in the history
  • Loading branch information
busunkim96 committed Sep 15, 2020
1 parent 7a2694e commit abc5070
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions samples/beta/cancel_operation.py
@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
#
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

# [START automl_cancel_operation]

from google.cloud import automl_v1beta1


def sample_cancel_operation(project, operation_id):
"""
Cancel Long-Running Operation
Args:
project Required. Your Google Cloud Project ID.
operation_id Required. The ID of the Operation.
"""

client = automl_v1beta1.AutoMlClient()

operations_client = client.transport._operations_client

# project = '[Google Cloud Project ID]'
# operation_id = '[Operation ID]'
name = "projects/{}/locations/us-central1/operations/{}".format(
project, operation_id
)

operations_client.cancel_operation(name)

print(u"Cancelled operation: {}".format(name))


# [END automl_cancel_operation]


def main():
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--project", type=str, default="[Google Cloud Project ID]")
parser.add_argument("--operation_id", type=str, default="[Operation ID]")
args = parser.parse_args()

sample_cancel_operation(args.project, args.operation_id)


if __name__ == "__main__":
main()

0 comments on commit abc5070

Please sign in to comment.