Assume for a chat room I would like to display for the user how many users are online at this moment(basically how many people watching now feature).
What I thought of is using some redis counter for each actioncable channel, increment and decrement this counter when a client is connected or disconnected to the channel, and there we go, however the problem with this approach is that if the some client opened a web page, then the counter will be incremented, and if the server then went down for some time, and that client closed the web page, then the disconnected event won't be listened to, so the counter will not be decremented and its value will be always wrong.
I think this approach can be enhanced if I can catch the event when the server is closed so that I set all such redis counters to zero, however not sure how to catch such event (I'm using nginx with passenger). So any help ?