[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-11-22。"],[],[],null,["# Long-running operations\n\nFor some API calls, Vertex AI returns operation names. These API calls\nstart operations that require time to complete and are known as *long-running\noperations*. For example, creating a dataset, deleting an endpoint, or exporting\na model are all long-running operations. You can use helper methods along with\noperation names to get the status of or cancel a long-running operation, as\ndescribed in the following sections.\n| **Note:** If you are using the Google Cloud console, the console shows the status of the operation and automatically updates the status when an operation is complete.\n\nGetting the status of an operation\n----------------------------------\n\nTo get the operation status, use the operation name that was in the response\nwhen you requested a long-running operation. For example, when you create a\ndataset, Vertex AI returns an operation name such as: \n\n`projects/`\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e`/locations/`\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`/datasets/`\u003cvar translate=\"no\"\u003eDATASET_ID\u003c/var\u003e`/operations/`\u003cvar translate=\"no\"\u003eOPERATION_ID\u003c/var\u003e\n\nYou can poll the operation at regular intervals so that you know when an\noperation completes. \n\n### REST\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003eOPERATION_NAME\u003c/var\u003e: The operation name that is returned when you start a long-running operation, such as `projects/`\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e`/locations/`\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`/datasets/`\u003cvar translate=\"no\"\u003eDATASET_ID\u003c/var\u003e`/operations/`\u003cvar translate=\"no\"\u003eOPERATION_ID\u003c/var\u003e\n\n\nHTTP method and URL:\n\n```\nGET https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME\n```\n\nTo send your request, choose one of these options: \n\n#### curl\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nExecute the following command:\n\n```\ncurl -X GET \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n \"https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME\"\n```\n\n#### PowerShell\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nExecute the following command:\n\n```\n$cred = gcloud auth print-access-token\n$headers = @{ \"Authorization\" = \"Bearer $cred\" }\n\nInvoke-WebRequest `\n -Method GET `\n -Headers $headers `\n -Uri \"https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME\" | Select-Object -Expand Content\n```\n\nIn the output, the `metadata` object contains information that is\nspecific to the request type. The `done` field indicates whether the\noperation is complete. If the operation is complete, the `response`\nobject contains results from the operation.\n\n```\n{\n \"name\": \"projects/123456789012/locations/us-central1/datasets/1234567890123456789/operations/1223344556677889900\",\n \"metadata\": {\n \"@type\": \"type.googleapis.com/google.cloud.aiplatform.v1.CreateDatasetOperationMetadata\",\n \"genericMetadata\": {\n \"createTime\": \"2020-10-12T16:00:44.686500Z\",\n \"updateTime\": \"2020-10-12T16:01:06.115081Z\"\n }\n },\n \"done\": true,\n \"response\": {\n \"@type\": \"type.googleapis.com/google.cloud.aiplatform.v1.Dataset\",\n \"name\": \"projects/123456789012/locations/us-central1/datasets/1234567890123456789\",\n \"displayName\": \"image_dataset\",\n \"metadataSchemaUri\": \"gs://google-cloud-aiplatform/schema/dataset/metadata/image_1.0.0.yaml\",\n \"labels\": {\n \"aiplatform.googleapis.com/dataset_metadata_schema\": \"IMAGE\"\n },\n \"metadata\": {\n \"dataItemSchemaUri\": \"gs://google-cloud-aiplatform/schema/dataset/dataitem/image_1.0.0.yaml\"\n }\n }\n}\n```\n\n\u003cbr /\u003e\n\nCanceling an Operation\n----------------------\n\nYou can cancel a long-running operation so that you can stop it before the\noperation completes. When you successfully cancel an operation, the operation\nisn't deleted; instead, the operation stops with an error code of `1` and\nwith a `CANCELLED` message. Note that the cancellation is not guaranteed to\nsucceed. \n\n### REST\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003eOPERATION_NAME\u003c/var\u003e: The operation name that is returned when you start a long-running operation, such as `projects/`\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e`/locations/`\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`/datasets/`\u003cvar translate=\"no\"\u003eDATASET_ID\u003c/var\u003e`/operations/`\u003cvar translate=\"no\"\u003eOPERATION_ID\u003c/var\u003e\n\n\nHTTP method and URL:\n\n```\nPOST https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME:cancel\n```\n\nTo send your request, choose one of these options: \n\n#### curl\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nExecute the following command:\n\n```\ncurl -X POST \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Content-Type: application/json; charset=utf-8\" \\\n -d \"\" \\\n \"https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME:cancel\"\n```\n\n#### PowerShell\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nExecute the following command:\n\n```\n$cred = gcloud auth print-access-token\n$headers = @{ \"Authorization\" = \"Bearer $cred\" }\n\nInvoke-WebRequest `\n -Method POST `\n -Headers $headers `\n -Uri \"https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME:cancel\" | Select-Object -Expand Content\n```\n\nYou should receive a successful status code (2xx) and an empty response.\n\n\u003cbr /\u003e"]]