Membatalkan operasi yang berjalan lama
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Membatalkan operasi yang berjalan lama (LRO)
Mempelajari lebih lanjut
Untuk dokumentasi mendetail yang menyertakan contoh kode ini, lihat artikel berikut:
Contoh kode
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content explains how to cancel a long-running operation (LRO) within Google Cloud's Document AI service.\u003c/p\u003e\n"],["\u003cp\u003eIt provides a Python code sample demonstrating the use of the \u003ccode\u003ecancel_operation\u003c/code\u003e method, utilizing the \u003ccode\u003eCancelOperationRequest\u003c/code\u003e from the \u003ccode\u003egoogle.longrunning\u003c/code\u003e library.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves authenticating to Document AI using Application Default Credentials and specifying the location and operation name.\u003c/p\u003e\n"],["\u003cp\u003eThe provided sample can be run with a location other than "us" by setting the \u003ccode\u003eapi_endpoint\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Cloud Sample Browser is provided as a resource to help look for other code examples.\u003c/p\u003e\n"]]],[],null,["# Cancel a long-running operation\n\nCancels a long-running operation (LRO)\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Managing long-running operations (LROs)](/document-ai/docs/long-running-operations)\n\nCode sample\n-----------\n\n### Python\n\n\nFor more information, see the\n[Document AI Python API\nreference documentation](/python/docs/reference/documentai/latest).\n\n\nTo authenticate to Document AI, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n from google.api_core.client_options import ClientOptions\n from google.cloud import documentai # type: ignore\n from google.longrunning.operations_pb2 import CancelOperationRequest # type: ignore\n\n # TODO(developer): Uncomment these variables before running the sample.\n # location = \"YOUR_PROCESSOR_LOCATION\" # Format is \"us\" or \"eu\"\n # operation_name = \"YOUR_OPERATION_NAME\" # Format is \"projects/{project_id}/locations/{location}/operations/{operation_id}\"\n\n\n def cancel_operation_sample(location: str, operation_name: str) -\u003e None:\n # You must set the `api_endpoint` if you use a location other than \"us\".\n opts = ClientOptions(api_endpoint=f\"{location}-documentai.googleapis.com\")\n client = documentai.https://cloud.google.com/python/docs/reference/documentai/latest/google.cloud.documentai_v1.services.document_processor_service.DocumentProcessorServiceClient.html(client_options=opts)\n\n request = CancelOperationRequest(name=operation_name)\n\n # Make CancelOperation request\n client.https://cloud.google.com/python/docs/reference/documentai/latest/google.cloud.documentai_v1.services.document_processor_service.DocumentProcessorServiceClient.html#google_cloud_documentai_v1_services_document_processor_service_DocumentProcessorServiceClient_cancel_operation(request=request)\n print(f\"Operation {operation_name} cancelled\")\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=documentai)."]]