Thursday, February 28, 2013

Re: StreamingHttpResponse into a Template

Not sure if this is what you meant by "we'll probably keep the javascript reloading to process junks, waiting for the support of celery", but one option without celery is to have the initial request save a bunch of "PendingEmail" objects in the database and then redirect you to a "send_queued_emails" page that sends as many emails as it can in 5 seconds and then returns a page telling you how many it needs to send remaining and javascript to refresh the page immediately (if you use browsers that will show a blank page as soon as the refresh is initiated, you can use ajax or something for these requests).

Something somewhat closer to the celery option, but possible to set up on slightly more restrictive systems is to do the same thing with "PendingEmail" objects and set up a cron job to run a django management command every minute that consumes as many PendingEmail objects it can in 55 seconds.

For either of these solutions, make sure autocommit is enabled for those functions and that you mark an email as sent before you start the api call otherwise if somehow two things are consuming from the same queue you could send duplicate emails. Alternatively (or additionally) you could even create a lock-file or some similar thing to make sure only one thing is consuming from the queue at a time.

On Thursday, February 28, 2013 1:31:29 AM UTC-8, Stefano Tranquillini wrote:
Yes, you are perfectly right about the fact that this is a bad implementation.
the fact is that where i host the code it does not support celery (so far). so i've to find out a workaround to be able to process a bunch of external APIs Call (that include the one for sending email). 
we'll probably keep the javascript reloading to process junks, waiting for the support of celery.

BTW: the StreamingHttpResposnse, when should it be used? i get the example on the docs about writing a cvs, pdf or similar, but, what else?

Thanks for the help.

On Wednesday, February 27, 2013 6:23:52 PM UTC+1, Stefano Tranquillini wrote:

Django 1.5 is just came out and it ships the StreamingHttpResponse. 

What i want to do is to print the output of a stream response into a template, having for example a bar that grows based on the streamed data (something similar to a loading bar).

so far i've found a solution that basically is to write the pieces of the final html page into the generator function, so each yield does a render_to_text of a piece of the final html page (i splitted it manually) putting each time the data just processed. 

The problem of this solution is that i can't have the loading bar. What I'm able to have are incremental data, so i can print out the list of processed data, but it's different to what i want to do.

Is there a way to do what i would like to do? 

thanks.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment