Los archivos de datos estructurados no se generan de forma instantánea. Display & Video 360 puede tardar desde unos segundos hasta horas en generar tus SDF.
Para determinar si tu tarea finalizó, recupera la operación con regularidad usando sdfdownloadtasks.operations.get y verifica si el campo done es True y la tarea finalizó. Este proceso se conoce como "sondeo".
Si la tarea finalizó, se establece el campo response o error. Si se propaga el campo error, la tarea falló y los detalles sobre la falla están disponibles en el objeto Status resultante. Si el campo response está completado, Display & Video 360 generó correctamente los SDF. Descarga los archivos resultantes desde la ubicación proporcionada en response.resourceName.
Una implementación de sondeo ineficiente que verifica un informe de ejecución prolongada consume gran parte de tu cuota de solicitudes a la API. Para limitar los reintentos y conservar la cuota, usa la retirada exponencial.
A continuación, se muestra cómo sondear una operación de descarga de SDF con retirada exponencial:
# Provide the name of the sdfdownloadtask 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 sdfdownloadtasks.operations.get request. get_request = service.sdfdownloadtasks().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 resulting files can be ' f'downloaded at {operation["response"]["resourceName"]}.') break elif time.time() - start_time > max_retry_elapsed_time: print("SDF generation 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))