Cloud Translation API의 일부 메서드는 장기 실행 작업을 반환합니다. 이러한 메서드는 비동기적이며 메서드가 응답을 반환하면 작업이 완료되지 않을 수 있습니다. 작업 상태를 확인하거나 작업을 취소할 수 있습니다.
작업 상태
다음은 작업 상태를 폴링하는 방법을 보여줍니다.
operation
리소스의 get
메서드를 호출합니다.
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- PROJECT_NUMBER_OR_ID: Google Cloud 프로젝트의 숫자 또는 영숫자 ID
- location-id: Cloud Storage 버킷을 위해 선택한 위치
- operation-id: 위에서 받은 작업 ID
HTTP 메서드 및 URL:
GET https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/location-id /operations/operation-id
요청을 보내려면 다음 옵션 중 하나를 펼칩니다.
cURL(Linux, macOS, Cloud Shell)
다음 명령어를 실행합니다.
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:PROJECT_NUMBER_OR_ID " \
"https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/location-id /operations/operation-id "
PowerShell(Windows)
다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER_OR_ID " }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/location-id /operations/operation-id " | Select-Object -Expand Content
다음과 비슷한 JSON 응답이 표시됩니다.
{ "name": "projects/project-number /locations/location-id /operations/operation-id ", "metadata": { "@type": "type.googleapis.com/google.cloud.translation.v3.SomeOperationMetadata", "state": "SUCCEEDED", "submitTime": "2019-11-27T22:59:40Z" } }
작업이 완료되면 state
값 SUCCEEDED
이 반환됩니다.
작업 취소
다음은 작업을 취소하는 방법을 보여줍니다.
operation
리소스에서 cancel
메서드를 호출합니다.
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- PROJECT_NUMBER_OR_ID: Google Cloud 프로젝트의 숫자 또는 영숫자 ID
- LOCATION: 작업을 시작할 때 선택한 위치
- OPERATION_ID: 취소할 작업의 ID
HTTP 메서드 및 URL:
POST https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/LOCATION_ID /operations/OPERATION_ID :cancel
요청을 보내려면 다음 옵션 중 하나를 펼칩니다.
cURL(Linux, macOS, Cloud Shell)
다음 명령어를 실행합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:PROJECT_NUMBER_OR_ID " \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/LOCATION_ID /operations/OPERATION_ID :cancel"
PowerShell(Windows)
다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER_OR_ID " }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/LOCATION_ID /operations/OPERATION_ID :cancel" | Select-Object -Expand Content
성공 상태 코드(2xx)와 빈 응답을 받게 됩니다.
추가 리소스
- 일반적인 문제 또는 오류를 해결하는 데 도움이 필요하면 문제 해결 페이지를 참조하세요.