I'd rip out the non-db stuff from the form.save() method and put those
in an asynchronous queue. Then you can have another process which
polls the queue and performs these other tasks after the database
save.

So for example, you would do the following:

instance = form.save()
# push your task to the queue
return HttpResponse('Done!')

Celery will do what I've described above nicely for you.

On Dec 2, 2:41 pm, brian <[email protected]> wrote:
> I'm having problems with a save method taking too long and the user
> thinking there is a problem with the website so they hit refresh which
> causes the data to be submitted multiple times.
>
> I have this in the view:
> -------------------------------------
> if form.is_valid():
>   form.save()
>   return HttpResponseRedirect('/thanks/')
> -------------------------------------
>
> The save method takes a little time.  It saves to db, sends a couple
> of emails, and interfaces with another software package(which is the
> time hog).  I want to be able to show the thanks page and then call
> the save method.
>
> It seems like celery(http://www.celeryproject.org/) is the best
> choice.  When I read the doc it said because of race conditions, be
> careful of passing models to celery tasks.  With my form I want it to
> save a unique instance for every time the form is submitted so I think
> I can pass the form to the task.
>
> Does anyone have suggestions or other recommendations about this?  Is
> there an easier way to do this?
>
> Brian

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to