Question

Im not really sure what to search for on this subject.

I have a Pylons back end which loops over a list of email addresses in a database and then displays them on a web page. What I would like to do is have a loading section (as there are some other processes which take quite a while) to show which email address is currently being proccessed.

i.e
"currently processing: example@internet.com"
"currently processing: example2@internet.com"

Im open to using any technology available, although I suspect AJAX would be the answer. Im just a bit stumped for what to do, as if I return something to the front end web page, the process will end! There must be some sort of parallel processing, but I dont know how to go about it. So how can I show which email address is being processed on screen?

Python

emails = [a,b,c]
for x in emails:
   return x

Javascript

function displayProcess(email){
$('#emailDisplay').val(email)
};
Was it helpful?

Solution

You should use some sort of job queue for long-lasting tasks. Celery is quite popular in Python world. Jobs could report their status to some sort of quick and temporary data store, like Redis and JavaScript could poll for those statuses using AJAX each, let's say, 5 seconds (I'm assuming it doesn't really matter if something has been processed 2 or 5 seconds ago).

edit

Just to clarify - in model I'm describing JavaScript doesn't call Redis directly. It uses some sort of service dumping needed data to JSON or XML.

OTHER TIPS

You dont loop over list, because on first return your loop is broke.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top