장기 실행 작업

일부 API 호출의 경우 Vertex AI는 작업 이름을 반환합니다. 이러한 API는 완료하는 데 시간이 오래 걸리는 장기 실행 작업으로 알려진 시작 작업을 호출합니다. 예를 들어 데이터 세트 만들기, 엔드포인트 삭제, 모델 내보내기는 모두 장기 실행 작업입니다. 다음 섹션에서 설명하는 것처럼 작업 이름과 함께 도우미 메서드를 사용하여 장기 실행 작업의 상태를 가져오거나 취소할 수 있습니다.

작업 상태 가져오기

작업 상태를 가져오려면 장기 실행 작업을 요청할 때 응답에 있던 작업 이름을 사용합니다. 예를 들어 데이터 세트를 만들 때 Vertex AI는 다음과 같은 작업 이름을 반환합니다.
projects/PROJECT_NUMBER/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID

작업을 일정한 간격으로 폴링하므로 작업이 완료되면 이를 알 수 있습니다.

REST

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • OPERATION_NAME: 장기 실행 작업을 시작할 때 반환되는 작업 이름입니다(예: projects/PROJECT_NUMBER/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID).

HTTP 메서드 및 URL:

GET https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME

요청을 보내려면 다음 옵션 중 하나를 선택합니다.

curl

다음 명령어를 실행합니다.

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME"

PowerShell

다음 명령어를 실행합니다.

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME" | Select-Object -Expand Content

출력에서 metadata 객체에는 요청 유형과 관련된 정보가 포함됩니다. done 필드는 작업 완료 여부를 나타냅니다. 작업이 완료되면 response 객체에 작업의 결과가 포함됩니다.

{
  "name": "projects/123456789012/locations/us-central1/datasets/1234567890123456789/operations/1223344556677889900",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.v1.CreateDatasetOperationMetadata",
    "genericMetadata": {
      "createTime": "2020-10-12T16:00:44.686500Z",
      "updateTime": "2020-10-12T16:01:06.115081Z"
    }
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.v1.Dataset",
    "name": "projects/123456789012/locations/us-central1/datasets/1234567890123456789",
    "displayName": "image_dataset",
    "metadataSchemaUri": "gs://google-cloud-aiplatform/schema/dataset/metadata/image_1.0.0.yaml",
    "labels": {
      "aiplatform.googleapis.com/dataset_metadata_schema": "IMAGE"
    },
    "metadata": {
      "dataItemSchemaUri": "gs://google-cloud-aiplatform/schema/dataset/dataitem/image_1.0.0.yaml"
    }
  }
}

작업 취소

장기 실행 작업을 취소하여 작업이 완료되기 전에 중지할 수 있습니다. 작업을 성공적으로 취소하면 작업은 삭제되지 않습니다. 대신 오류 코드 1CANCELLED 메시지와 함께 작업이 중지됩니다. 취소 작업은 반드시 성공하지는 않습니다.

REST

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • OPERATION_NAME: 장기 실행 작업을 시작할 때 반환되는 작업 이름입니다(예: projects/PROJECT_NUMBER/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID).

HTTP 메서드 및 URL:

POST https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME:cancel

요청을 보내려면 다음 옵션 중 하나를 선택합니다.

curl

다음 명령어를 실행합니다.

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME:cancel"

PowerShell

다음 명령어를 실행합니다.

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME:cancel" | Select-Object -Expand Content

성공 상태 코드(2xx)와 빈 응답을 받게 됩니다.