Created
November 7, 2016 03:34
-
-
Save douglasmiranda/fb18cbeb92cc3730da6a5a829af773c7 to your computer and use it in GitHub Desktop.
Django Atomic Requests + Background Jobs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.vinta.com.br/blog/2016/database-concurrency-in-django-the-right-way/ | |
from django.db import transaction | |
# ... | |
class SimpleHandler(View): | |
def get(self, request, *args, **kwargs): | |
myData = Data.objects.create(name='Dummy') | |
transaction.on_commit(lambda: do_stuff.delay(myData.pk)) | |
return HttpResponse('pk: {pk}'.format(pk=myData.pk)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment