קבלת סטטוס של פעולה

חלק מהפעולות שאתם מבקשים הן פעולות ארוכות טווח, כמו יצירת קבוצת מוצרים באמצעות ייבוא בכמות גדולה, מחיקה של קבוצת מוצרים ומחיקה של מוצרים יתומים. סוגי הבקשות האלה יחזירו JSON עם מזהה פעולה שבו אפשר להשתמש כדי לקבל את הסטטוס של הפעולה.

לדוגמה, בקשה למחיקה של קבוצת אובייקטים (purge) מחזירה את ה-JSON הבא:

{
"name": "projects/project-id/locations/location-id/operations/bc4e1d412863e626"
}

במקרה הזה, מזהה הפעולה הוא bc4e1d412863e626. בדוגמאות הבאות אפשר לראות איך מקבלים את הסטטוס של הפעולה הזו באמצעות המזהה הזה.

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
  • LOCATION_ID: מזהה מיקום תקין. מזהי מיקום תקינים: us-west1,‏ us-east1,‏ europe-west1 ו-asia-east1.
  • OPERATION_ID: מזהה הפעולה. המזהה הוא הרכיב האחרון בשם של הפעולה. לדוגמה:
    • שם הפעולה: projects/PROJECT_ID/locations/LOCATION_ID/operations/bc4e1d412863e626
    • מזהה הפעולה: bc4e1d412863e626

ה-method של ה-HTTP וכתובת ה-URL:

GET https://vision.googleapis.com/v1/locations/location-id/operations/operation-id

כדי לשלוח את הבקשה אתם צריכים לבחור אחת מהאפשרויות הבאות:

curl

מריצים את הפקודה הבאה:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
"https://vision.googleapis.com/v1/locations/location-id/operations/operation-id"

PowerShell

מריצים את הפקודה הבאה:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://vision.googleapis.com/v1/locations/location-id/operations/operation-id" | Select-Object -Expand Content
הפלט שיוצג לכם אחרי פעולת ניקוי של קבוצת מוצרים אמור להיראות כך:
{
  "name": "locations/location-id/operations/operation-id",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.vision.v1.BatchOperationMetadata",
    "state": "SUCCESSFUL",
    "submitTime": "2019-09-04T15:58:39.131591882Z",
    "endTime": "2019-09-04T15:58:43.099020580Z"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.vision.v1.PurgeProductsRequest",
    "parent": "projects/project-id/locations/location-id",
    "productSetPurgeConfig": {
      "productSetId": "project-set-id"
    },
    "force": true
  }
}

הפלט שיוצג לכם אחרי השלמת הפעולה purge orphaned products operation אמור להיות דומה לזה:

{
  "name": "locations/location-id/operations/operation-id",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.vision.v1.BatchOperationMetadata",
    "state": "SUCCESSFUL",
    "submitTime": "2019-09-04T16:08:38.278197397Z",
    "endTime": "2019-09-04T16:08:45.075778639Z"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.vision.v1.PurgeProductsRequest",
    "parent": "projects/project-id/locations/location-id",
    "deleteOrphanProducts": true,
    "force": true
  }
}