1

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
2
  • Can you add the task to the question? Commented Feb 5, 2022 at 18:56
  • added, please review. Commented Feb 6, 2022 at 5:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.