I have used celery apply_async (also tried delay) with django. The task executes only 3 out of 10 queries where I am performing an update operation on mongo db database. (I am using pymongo) Only the last update query is executed 3 out of 10 times, rest are ok.
@shared_task
def func(user_id, video_id, duration, timestamp):
db.watchdata.insert_one({"video":ObjectId(video_id),"user":ObjectId(user_id),"duration":float(duration),"timestamp":int(timestamp)})
db.feed_data.update_one({"user":ObjectId(user_id)},{"$addToSet":{"watched":ObjectId(video_id)}})
doc=db.feed_data.find_one({"user":ObjectId(user_id)})
total_time=doc['total_watch_time']+float(duration)
week_time=doc['previous_seven_days']+float(duration)
today_time=doc['today_watch_time']+float(duration)
db.feed_data.update_one({"user":ObjectId(user_id)},{"$set":{"total_watch_time":total_time,"previous_seven_days":week_time,"today_watch_time":today_time}})
return