Can I use Django Channels to solve this architectural prolem?

2016-11-15 Thread psaod8fza9s
Hi there,

I want to develop a Django site where users have the possibility to 
interact with systemd services in realtime and to see the log output in 
realtime.

I sketched up a quick draft on my idea how this could work: 
https://i.imgur.com/pd5uLtl.jpg


One simplified use-case would be:

  1. User visits Django website.
  2. User chooses one of many systemd services. each service would be 
represented by a single webpage, eg. /services/id/1, /services/id/2...
  3. User gets presented a realtime log, the source being either journald 
or lastlog-file on the file system.
  4. User clicks on Stop button.
  5. Service gets stopped.
  6. User receives exit codes, etc. in a readable format.
  7. User clicks on start button
  8. User receives exit codes (started successfully/failed/etc) in a 
readable format.
  9. User leaves Django website.

I wrote a simple Controller (MyController.py) that connects to the systemd 
interface of the dbus, to controllthe systemd services and listen for 
property changes, but also to read logfiles from the file system. I inteded 
MyController to run as root and sit between Django and dbus/systemd.

I would think WebSockets are the best solution to deal with the realtime 
log display in 3) and with the live interaction in 4) 5) 6) 7) and 8).
I recently read about Django Channels and I believe this would be the 
solution to Django<(WebSocket)->User.

But somehow Django needs to talk to my MyController.py daemon for starting 
and stopping, as well as getting the systemd exit codes across to the User 
in realtime.
I believe I cannot use xmlrpc, because that is a pure Request<->Response 
principle. But a live log is continuous, and if you start a service, that 
could take ten seconds and I really want to have quick response times. I 
also thought about background job management, but I prefer WebSockets over 
this, so I don't have to implement multiple technologies.

My question would be this: Could I somehow use Channels to connect 
MyController with Django and vice versa, similar to xmlrpc but so that both 
sides can send?

I am open for all ideas at this point, but I prefer to implement only one 
kind of technology if that would be possible.

Thanks in advance!

psaodwhatevermynameis.

-- 
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+unsubscr...@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/4224be09-059f-42e5-8352-b3aad34bf5b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


I don't understand the second paragraph on the Getting Started with Channels documentation

2016-11-17 Thread psaod8fza9s

>
> When you run Django out of the box, it will be set up in the default 
> layout - where all HTTP requests (on the http.request channel) are routed 
> to the Django view layer.


What is meant with "on the http.request channel" in the context of "out of 
the box"? Out of the box Django does not know channels.

{I actually re-read that paragraph a couple of times at this point.}

Okay ... do they mean *after* I installed Channels? Because then maybe it 
would be better to say "When you run Django with Channels out of the box". 
People like me who never got really serious with Django and want to have a 
quick look at some Channels code may be confused by that sentence in that 
way.

Cheers.

-- 
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+unsubscr...@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/04a560fd-148b-40a6-abb0-a24438ff3509%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can I use Django Channels to solve this architectural prolem?

2016-11-18 Thread psaod8fza9s
Hi Andrew, thanks for the advice. Since I implement websockets to serve my 
users the live logs, I would just route the service commands (e.g. 
"service.start") through the websocket, too. That way I also don't have to 
block other things while waiting for the response whether the command was 
successful or not.

I read into the documentation and setup a basic web socket site that is 
working (woohoo). The rest is just more reading and learning and trial and 
error, but I am confident I get this working.

However, how would I connect my Controller to the Channel layer, setup a 
consumer and a producer? I got it working for Django and websockets, but 
from a standalone python app? hmmm..

- psaodicantremembertherest

On Wednesday, 16 November 2016 06:51:19 UTC+1, Andrew Godwin wrote:

> You could use channels (well, ASGI, it's lower-level interface) for the 
> interconnect:
>
>  - Use channels for signals from the web service to the controller daemon 
> (maybe "service.stop" or "service.start" with the service name in the 
> message payload). You can trigger these from simple AJAX or GET views, no 
> need for websocket here.
>  - Send the log continuously out to a Group as it's received, one group 
> per service. Then, when someone joins and wishes to tail the log, tie in 
> their socket to the group.
>
> However, this does not supply log playback of lines before a client joins, 
> so you'd have to fill in that gap. In the end, you're probably looking at 
> some sort of datastore in the middle there to store logs and then replay 
> them into a socket as it joins.
>
> Andrew
>
> On Tue, Nov 15, 2016 at 2:27 PM, > wrote:
>
>> Hi there,
>>
>> I want to develop a Django site where users have the possibility to 
>> interact with systemd services in realtime and to see the log output in 
>> realtime.
>>
>> I sketched up a quick draft on my idea how this could work: 
>> https://i.imgur.com/pd5uLtl.jpg
>>
>>
>> One simplified use-case would be:
>>
>>   1. User visits Django website.
>>   2. User chooses one of many systemd services. each service would be 
>> represented by a single webpage, eg. /services/id/1, /services/id/2...
>>   3. User gets presented a realtime log, the source being either journald 
>> or lastlog-file on the file system.
>>   4. User clicks on Stop button.
>>   5. Service gets stopped.
>>   6. User receives exit codes, etc. in a readable format.
>>   7. User clicks on start button
>>   8. User receives exit codes (started successfully/failed/etc) in a 
>> readable format.
>>   9. User leaves Django website.
>>
>> I wrote a simple Controller (MyController.py) that connects to the 
>> systemd interface of the dbus, to controllthe systemd services and listen 
>> for property changes, but also to read logfiles from the file system. I 
>> inteded MyController to run as root and sit between Django and dbus/systemd.
>>
>> I would think WebSockets are the best solution to deal with the realtime 
>> log display in 3) and with the live interaction in 4) 5) 6) 7) and 8).
>> I recently read about Django Channels and I believe this would be the 
>> solution to Django<(WebSocket)->User.
>>
>> But somehow Django needs to talk to my MyController.py daemon for 
>> starting and stopping, as well as getting the systemd exit codes across to 
>> the User in realtime.
>> I believe I cannot use xmlrpc, because that is a pure Request<->Response 
>> principle. But a live log is continuous, and if you start a service, that 
>> could take ten seconds and I really want to have quick response times. I 
>> also thought about background job management, but I prefer WebSockets over 
>> this, so I don't have to implement multiple technologies.
>>
>> My question would be this: Could I somehow use Channels to connect 
>> MyController with Django and vice versa, similar to xmlrpc but so that both 
>> sides can send?
>>
>> I am open for all ideas at this point, but I prefer to implement only one 
>> kind of technology if that would be possible.
>>
>> Thanks in advance!
>>
>> psaodwhatevermynameis.
>>
>> -- 
>> 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/4224be09-059f-42e5-8352-b3aad34bf5b7%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 dj