There's a very common pattern for this kind of activity:
1) User requests /start page to get some data that is expensive to calculate
2) View for /start creates a Task object that represents the work to
be executed in the background.
3) An external process is running, waiting for new Task objects to be
created. Exactly how this is serviced is up to you, but the important
part is that the expensive calculation isn't performed in the view
code -- it's handled by a process external to the web server. Celery
is a common way to handle this sort of task; you can also knock
something together quickly with a script running under a cron (run
once per minute, find all new tasks, process each, then quit. Not
ideal for production, but it works as a proof of concept).
4) Once the task has been *created* (Not finished -- just created),
/start redirects to a /loading page.
5) /loading contains an ajax lookup that polls the completion status
of the task
6) The task executes and completes; on completion, the task is marked
as "complete".
7) Once the task is complete, /loading reports the completion, and
redirects to /finished to display the results of the calculation.
At every step, the web server's interaction is short lived -- create a
task; check if the task is complete; display the result of the task --
so it scales well. If you're careful about the design of your task
processor, you can make sure that this processor scales too; e.g., add
a second Celery processor for the task, and you've just doubled your
capacity.
Hope this helps!
Yours,
Russ Magee %-)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Russ mentioned it in passing, but I'll point it out for clarity: Celery is a great framework for handling background tasks.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/TwtPwcwjzvkJ.