ActionCable external broadcaster

Hi,

I apologise if this has already been answered, but I cannot find anything relating to the topic when searching around.

I am using Rails 5.0.0.1 with ActionCable 5.0.0.1

What I am trying to achieve is creating a dashboard page, with various graphs and indicators that are updated in real time or semi-real time. I have managed to get ActionCable setup and working with a few graphs, and now I would like to use it to update a graph that shows the server load. Previously I had this working with js making a query to a controller action every second or so, which would then call a bash script, and return the results. I would like to convert this to a websocket, but I cannot find a way to do this cleanly.

What I have tried so far:

  • Create a script similar to the ones in /bin that inherit the rails environment and settings, and try to broadcast to the websocket. I realised that this doesn’t work as its creating a new instance of the app environment, so wont broadcast to the currently running rails server.

  • Create a client based off of https://github.com/NullVoxPopuli/action_cable_client, however this has the drawback that the client will also receive its own updates.

Can anyone suggest anything else that might work, or a better way to do this?

Thanks

/Cole

Ok, so replying to my own post because I think I realised the solution.

The testing done as mentioned before was done with a ‘development’ environment, and ActionCable set to async. In production you would use a redis server which would be needed due to multiple instances running. Therefore I believe that I could use the first solution mentioned ( the script in /bin which inherits or starts a rails environment ) and it should then send to the redis server and everything should work. Please correct me if I am wrong here.

Also the second option then would be to directly connect to the redis server and insert the messages for the various channels directly.