0

Is it possible to submit a django form to run 2-3 large tasks at the backend and display the user a page for status/progress of the tasks running and display the output on completion.

I have a function as below in my view.py file which executes large tasks. I want that while the tasks are been running in the back-end on my server(ubuntu), instead of showing the user with the page/browser loading (which hangs for huge tasks), I want to show a page to show the tasks status/progress.

views.py

def test(request) :

    if request.method == 'POST': # If the form has been submitted...

        form = TestForm(request.POST)

        if form.is_valid(): # All validation rules pass
            form_data    = form.cleaned_data

            ## Get the form data and use it
            output, error = executeCommand("##Perform the required action with the form data")

            if error == '' :

                return HttpResponse('Work Done !! Thanks')
            else :
                return HttpResponse('Error Occurred')

    else:
         form = TesForm() # An unbound form

    return render_to_response("test.html", { 'form' : form } , context_instance=RequestContext(request))

Any help/advice is greatly appreciated.

sunny
  • 708
  • 11
  • 23
  • 1
    To handle those use cases one usually uses message queues. See maybe http://stackoverflow.com/questions/454944/advice-on-python-django-and-message-queues – toabi May 02 '14 at 10:34
  • can i handle the form submission using ajax calls to avoid page loading (browser hang situation) and session timeout situation if I don't want any status/progress to show – sunny May 02 '14 at 12:08

1 Answers1

1

I think your webserver will get stucked if your "executeCommand" take very long time to finish.

You might use message queues as suggested by toabi.

You might have a look on django-celery.

chitak
  • 68
  • 6