अपलोड की गई स्ट्रक्चर्ड डेटा फ़ाइलों से, संसाधन तुरंत नहीं बनाए या अपडेट किए जाते. Display & Video 360 को आपके एसडीएफ़ प्रोसेस करने और अपडेट करने में कुछ सेकंड से लेकर कई घंटे लग सकते हैं. एक साथ कई फ़ाइलें अपलोड की जा सकती हैं. हालांकि, यह ज़रूरी है कि उनमें कोई भी ओवरलैप होने वाला संसाधन न हो.
यह पता करने के लिए कि आपका टास्क पूरा हो गया है या नहीं, sdfuploadtasks.operations.get का इस्तेमाल करके ऑपरेशन को नियमित तौर पर वापस पाएं. साथ ही, देखें कि done फ़ील्ड True है और टास्क पूरा हो गया है. इस प्रोसेस को "पोलिंग" कहा जाता है.
अगर टास्क पूरा हो गया है, तो response या error फ़ील्ड सेट किया जाता है. अगर error फ़ील्ड में वैल्यू मौजूद है, तो इसका मतलब है कि टास्क पूरा नहीं हुआ. टास्क पूरा न होने की वजह के बारे में जानकारी, Status ऑब्जेक्ट में मौजूद होती है. अगर response फ़ील्ड में वैल्यू मौजूद है, तो फ़ील्ड को SdfUploadTask असाइन किया जाएगा. इसका मतलब है कि Display & Video 360 ने अपलोड किए गए एसडीएफ़ को प्रोसेस कर लिया है. SdfUploadTask.resourceName फ़ील्ड में दी गई जगह से, नतीजे की फ़ाइलें डाउनलोड करें.
पॉलिंग को सही तरीके से लागू न करने पर, लंबे समय तक चलने वाली रिपोर्ट की जांच की जाती है. इससे आपके एपीआई अनुरोध के कोटे का ज़्यादा इस्तेमाल होता है. फिर से कोशिश करने की संख्या को सीमित करने और कोटे को बचाने के लिए, एक्सपोनेंशियल बैकऑफ़ का इस्तेमाल करें.
यहां एक्स्पोनेंशियल बैकऑफ़ का इस्तेमाल करके, एसडीएफ़ अपलोड करने की प्रोसेस को पोल करने का तरीका बताया गया है:
# 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))