Tuesday, November 29, 2016

Re: Django and asynchronous tasks

Hi All

I spent several days reading and searching examples of how to implement channels. The current status of my project is as follows:
  • I have a page which lets the user enter the data used for the offline calculations, a POST request is send
  • the post request is handled and I can forward these data to a rq-worker, after which I open a basic web-page showing the input data. This page should also hold the results of the asynchronous calculations
  • the rq-worker starts the requested download of data from a site and I store the data in the apps (gnsspredict) directory. The rq-worker stops with a success reported in the log.
  • not yet implemented, but this is similar to the download thread, I shall further launch 2 to 3 workers to split up the work so that I can inform the user of the progress of the async calculations
But this is where I do not know what to do next.

As far as I understand 
  • the rq-worker can send its results using a dictionary to a 'reply-channel', but where does this channel goes to? 
  • of the few complete working examples on github I found I assume that I have to write a javascript (which I never used) to treat the results from the worker thread? I also remark that the javascript has as name 'function()', is this always the case? If so, for all 3 to 4 workers how do I write a script that takes action on which asyn cthread that has finished?
All help is appreciated

Thanks
Alain




On Thursday, 10 November 2016 11:55:01 UTC+1, ludovic coues wrote:
Websocket provide a way for server to send information to the client
without waiting for input from the client.

Django channels [1] is a project to bring native support of websocket
to django. There are alternatives which might involve a bit more of
work

[1] https://channels.readthedocs.io/en/stable/

2016-11-10 11:38 GMT+01:00 Antonis Christofides <ant...@djangodeployment.com>:
> Is there no mechanism that when the background tasks finishes to have a web
> page called which could display the results?
>
> Web pages cannot be "called". They are loaded by the browser. So, what you
> want is a mechanism that notifies the browser that an event has occurred in
> the server. That mechanism is comet.
>
> Antonis Christofides
> http://djangodeployment.com
>
> On 2016-11-10 11:54, Alain Muls wrote:
>
> Hi
>
> Tx for the suggestion but how do I reload a page after eg 30 seconds?
> Is there no mechanism that when the background tasks finishes to have a web
> page called which could display the results?
> I had a look at the signal mechanism of Django but I think that is not
> working since the background task is in another environment than the django
> apps which called it.
>
> bye/alain
>
> On Thursday, 10 November 2016 09:55:08 UTC+1, Antonis Christofides wrote:
>>
>> (Note: The most popular way to do asynchronous tasks is celery, but indeed
>> some
>> people prefer django-rq, which is said to be simpler. But your question is
>> not
>> affected by that.)
>>
>> I'm not an expert but I think that the "correct" way to do what you want
>> would
>> be to use comet (i.e. the opposite of ajax). However, if the work required
>> to
>> make that work is not justified by the budget or the business case, you
>> might be
>> able to get away with a message like "This information is being
>> (re)calculated.
>> Reload the page after half a minute to view the updated results." (That's
>> what I
>> did last time :-)
>>
>> Regards,
>>
>> Antonis
>>
>> http://djangodeployment.com
>>
>> On 2016-11-10 10:04, Alain Muls wrote:
>> > Hi All
>> >
>> > I am building a website which makes calculations about the visibility of
>> > satellites. These calculations take about half a minute so I do not want
>> > to
>> > block the site during this time. I found django-rq and was able to start
>> > a
>> > asynchronous task which handles the calculations.
>> >
>> > The problem I have is how do I find out when the calculations of the
>> > task
>> > thread are done so that I can direct the results to another web page
>> > which
>> > will display them?
>> >
>> > Thanks for your help
>> >
>> > Alain Muls
>> >
>> >
>>
> --
> 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...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6ae68ef3-6a52-4a59-a87b-3fcd627b4f26%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/0dcd7af0-6833-8174-363a-a68c5b3ff5c9%40djangodeployment.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c7aa0cfa-0371-4a85-a248-8f2f9715aadd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment