I’m sure there are many options in this regard. So I want to concentrate on what is best.
I combined ORM save and API request under the same function is this wrong for async?
How can I set this function as async?:
def main():
for product in inventories:
id = product["id"]
data = remote_api.products.get(id) #get information from remote server (type class)
if data["status"] = "success": #If the request is successful, proceed to the orm save stage
try:
offer = Offer.objects.get(id=id)
except ObjectDoesNotExist:
offer = Offer(id=id)
finally:
offer.price = data["product_price"] #value to save
offer.save()
Second Questions:
I need to set the rate limit to 5 when receiving data from the remote server. How can I handle this on the “for loop” side?