Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django non-blocking save?

Is there's way to call save() on an model in django, without waiting for a response from the db?
You could consider this async, though I need less, as async calls usually gives you callback- which I dont need here.
So basically I want -

SomeModel.objects.bulk_create([list of objects ]) , every say 1000 objects,
Without this line blocking my code. I will have no use in these rows in my code.
I'm looking for something simple, package like celery seems to offer way more than this..

like image 403
user3599803 Avatar asked Sep 06 '26 01:09

user3599803


1 Answers

As of 2016, Django is a web framework working (for the moment, if we are ignoring channels) taking a HTTP request "as argument" and returns a HTTP response as soon as possible.

This architecture means there is no concept of asynchronous operation in the framework. If you want to delay saving and returns response to the user without waiting, you can:

  • either run another thread/async block (which can be tedious with database transactions...) ;
  • services like IronWorker that allows you to queue operations to run async a.s.a.p ;
  • celery, that may bring too much features for your case but will do a better than job than some homemade solution.
like image 130
Maxime Lorant Avatar answered Sep 08 '26 01:09

Maxime Lorant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!