How can I tell if ActionCable is running?

In my application, running ActionCable is an optional feature. I’m looking for suggestions on how to check if ActionCable is running or not. I could of course have an Environment Variable that is set, but I thought the code might be nicer if I had some sort of ActionCable.server.running? type check…

Hi Eric. I don’t know ActionCable at all but I read this and I wanted to make sure I understand the question. Are you asking as to whether the gem for ActionCable is included and required?

Thanks for following up. So what I want is to detect if ActionCable is configured and there is a server running… My app doesn’t REQUIRE ActionCable, it’s more of a nice add on if people want to enable it. ActionCable requires Redis, and if folks don’t have redis running, then I get:

15:17:54 web.1 | from /usr/local/bundle/gems/redis-4.4.0/lib/redis.rb:82:in without_reconnect’`

15:17:54 web.1 | from /usr/local/bundle/gems/actioncable- listen’`

15:17:54 web.1 | from /usr/local/bundle/gems/actioncable- block in ensure_listener_running’`

I’m looking some sort of simple “switch” to turn on/off the ActionCable capabilities.

Where I have ended up is that I can catch some exceptions in various places if ActionCable is running ;-).

I thought maybe a check like ActionCable.server.nil? would do it, but that didn’t seem to be it. I’m going to check more later.

1 Like