আপলোড করা স্ট্রাকচার্ড ডেটা ফাইলগুলি তাৎক্ষণিকভাবে রিসোর্স তৈরি বা আপডেট করে না। ডিসপ্লে এবং ভিডিও 360 আপনার SDF প্রক্রিয়া করতে এবং ফলস্বরূপ আপডেট করতে কয়েক সেকেন্ড থেকে কয়েক ঘন্টা পর্যন্ত সময় নিতে পারে। একাধিক ফাইল একসাথে আপলোড করা যেতে পারে যতক্ষণ না সেগুলিতে কোনও ওভারল্যাপিং রিসোর্স থাকে।
আপনার কাজটি সম্পন্ন হয়েছে কিনা তা নির্ধারণ করতে, নিয়মিতভাবে sdfuploadtasks.operations.get ব্যবহার করে অপারেশনটি পুনরুদ্ধার করুন এবং পরীক্ষা করুন যে done ক্ষেত্রটি True কিনা এবং কাজটি সম্পন্ন হয়েছে কিনা। এই প্রক্রিয়াটি "পোলিং" নামে পরিচিত।
যদি কাজটি সম্পন্ন হয়, তাহলে response অথবা error ক্ষেত্রটি সেট করা হয়। যদি error ক্ষেত্রটি পূরণ করা হয়, তাহলে কাজটি ব্যর্থ হয়েছে এবং ব্যর্থতার বিশদ ফলাফলের Status অবজেক্টে পাওয়া যাবে। যদি response ক্ষেত্রটি পূরণ করা হয়, তাহলে ক্ষেত্রটিতে একটি SdfUploadTask বরাদ্দ করা হবে। এর অর্থ হল Display & Video 360 আপলোড করা SDF সফলভাবে প্রক্রিয়া করেছে। SdfUploadTask.resourceName ক্ষেত্রে প্রদত্ত অবস্থান থেকে ফলাফল ফাইলগুলি ডাউনলোড করুন ।
একটি অদক্ষ পোলিং বাস্তবায়ন যা দীর্ঘমেয়াদী রিপোর্ট পরীক্ষা করে আপনার API অনুরোধ কোটার অনেকটাই খরচ করে। পুনঃপ্রয়াস সীমিত করতে এবং কোটা সংরক্ষণ করতে, এক্সপোনেনশিয়াল ব্যাকঅফ ব্যবহার করুন।
এক্সপোনেনশিয়াল ব্যাকঅফ ব্যবহার করে SDF আপলোড অপারেশন কীভাবে পোল করবেন তা এখানে দেওয়া হল:
# 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))