สถานะงานแบบสำรวจ

ไฟล์ข้อมูลที่มีโครงสร้างที่อัปโหลดจะไม่สร้างหรืออัปเดตทรัพยากรทันที Display & Video 360 อาจใช้เวลาตั้งแต่ไม่กี่วินาทีจนถึงหลายชั่วโมงในการประมวลผล SDF และทำการอัปเดตที่ได้ คุณอัปโหลดหลายไฟล์พร้อมกันได้ ตราบใดที่ไฟล์เหล่านั้นไม่มีทรัพยากรที่ซ้ำกัน

หากต้องการดูว่างานเสร็จสมบูรณ์แล้วหรือไม่ ให้ดึงข้อมูลการดำเนินการเป็นประจำโดยใช้ sdfuploadtasks.operations.get และตรวจสอบว่าฟิลด์ doneเป็น True และงานเสร็จสมบูรณ์แล้ว กระบวนการนี้เรียกว่า "การสำรวจ"

หากงานเสร็จแล้ว ระบบจะตั้งค่าฟิลด์ response หรือ error หากมีการป้อนข้อมูลในฟิลด์ error แสดงว่างานไม่สำเร็จและ รายละเอียดเกี่ยวกับความล้มเหลวจะอยู่ในออบเจ็กต์ Status ที่ได้ หากฟิลด์ response มีข้อมูล ระบบจะกำหนด SdfUploadTask ให้กับฟิลด์ ซึ่งหมายความว่า Display & Video 360 ประมวลผล SDF ที่อัปโหลดเรียบร้อยแล้ว ดาวน์โหลดไฟล์ผลลัพธ์จากตำแหน่งที่ระบุในฟิลด์ SdfUploadTask.resourceName

การติดตั้งใช้งานการสำรวจที่ไม่มีประสิทธิภาพซึ่งตรวจสอบรายงานที่ใช้เวลานานจะใช้โควต้าคำขอ API ของคุณเป็นจำนวนมาก หากต้องการจำกัดการลองใหม่และ ประหยัดโควต้า ให้ใช้ Exponential Backoff

วิธีสำรวจการดำเนินการอัปโหลด SDF โดยใช้ Exponential Backoff มีดังนี้

# Import the necessary libraries
import random
import time

# Provide the name of the sdfuploadtask operation.
operation_name = operation-name

# Set the following values that control retry behavior while the operation
# is running.
# Minimum amount of time between polling requests. Defaults to 5 seconds.
min_retry_interval = 5
# Maximum amount of time between polling requests. Defaults to 5 minutes.
max_retry_interval = 5 * 60
# Maximum amount of time to spend polling. Defaults to 5 hours.
max_retry_elapsed_time = 5 * 60 * 60

# Configure the sdfuploadtasks.operations.get request.
get_request = service.sdfuploadtasks().operations().get(operation_name)

sleep = 0

start_time = time.time()
while True:
  # Get current status of the report.
  operation = get_request.execute()

  if "done" in operation:
    if "error" in operation:
      print(
        f'The operation finished in error with code '
        f'{operation["error"]["code"]}: {operation["error"]["message"]}')
    else:
      print(
        f'The operation completed successfully. The result files can be '
        f'downloaded at {operation["response"]["resourceName"]}.')
    break
  elif time.time() - start_time > max_retry_elapsed_time:
    print("Polling deadline exceeded.")
    break

  sleep = next_sleep_interval(sleep)
  print(
    f'Operation {operation_name} is still running, sleeping for '
    f'{sleep} seconds.')
  time.sleep(sleep)

def next_sleep_interval(previous_sleep_interval):
  """Calculates the next sleep interval based on the previous."""
  min_interval = previous_sleep_interval or min_retry_interval
  max_interval = previous_sleep_interval * 3 or min_retry_interval
  return min(max_retry_interval, random.randint(min_interval, max_interval))