Channels - Forward messages from a third party async source.

43 views
Skip to first unread message

Roger Gammans

unread,
Sep 1, 2017, 3:23:24 PM9/1/17
to django...@googlegroups.com
Hi all,

I'm trying to build a system with a Django frontend which displays live
information from other services on the backend (eg, the one running
python - not the browser) host.

To keep my dependencies as light as possibly I'm trying to avoid import
the settings file for django and channel into the backend services. And
run those a much lighter an simple process which concentrate on their
tasks.

I can easily create an async event in the backend processes; but to
get the channels layer to respond to it; It seems that I need to create
my own thread with it own tight loop doing something like:-

def forward_sensor_to_web(sensor_gen,dj_channel):
for sensor_data in sensor_gen():
Channel(dj_channel).send(sensor_data.as_json())


Obviously this needs to be kept running and restarted if the
loop/thread raises an exception etc.

Is there any extant best practice for how to set this sort of
architecture up using channels? Can I integrate the into the channels
main Aio loop? Or is channels to the best way to go?

I'm seeking to make sure I'm not missing anything; before thing start
to get hard to change.

Anybody got any thoughts?

--
Roger Gammans <rgam...@gammascience.co.uk>

Andrew Godwin

unread,
Sep 1, 2017, 3:39:42 PM9/1/17
to django...@googlegroups.com
Hey,

You can send onto Channels from anywhere, event loop or no, but if you want a background process that monitors an external source and forwards events from it you will need to write that yourself (I usually suggest management commands for this purpose).

I'm working on hopefully making it easier to write worker processes like this, but that's not something that's ready in the short term.

Andrew


--
Roger Gammans <rgam...@gammascience.co.uk>

--
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...@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/1504263403.30060.7.camel%40gammascience.co.uk.
For more options, visit https://groups.google.com/d/optout.

Roger Gammans

unread,
Sep 4, 2017, 4:50:56 AM9/4/17
to django...@googlegroups.com
Andrew,

Thanks for that.

Is there is anything I should avoid in my design and worker process to ensure it would be compatible with what goes in later versions of channels?
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.

Dan Tagg

unread,
Sep 4, 2017, 5:38:34 AM9/4/17
to django...@googlegroups.com
Hi Roger,

Have you seen Diamond (http://diamond.readthedocs.io/en/latest/) it may be just what you need on the client side. Graphite (the server process) runs on Django.

Dan


--
Roger Gammans <rgam...@gammascience.co.uk>

--
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...@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/1504263403.30060.7.camel%40gammascience.co.uk.
For more options, visit https://groups.google.com/d/optout.



--
Wildman and Herring Limited, Registered Office: 28 Brock Street, Bath, United Kingdom, BA1 2LN, Company no: 05766374
Reply all
Reply to author
Forward
0 new messages