Hyperstack.on_server? can do much better please
Currently Hyperstack.on_server? returns false if you not on the rails server (i.e. on the console or on in a sidekiq worker).
The system uses this to decide if it needs to forward any broadcasts to the server from, under the assumption that if you are not on the server you do not have access to the broadcast mechanism.
This assumption is pretty weak. The following are known cases where it doesn't matter:
you are using simple_poller (in this case you are going to shove the message into a queue, and wait for the next poll)
you are using action_cable NOT in async mode. (i.e. the connection data is stored in a database, not in the servers memory)
Not tested is pusher, and actually not tested (but I'm sure it would work is action_cable and redis)
Soooo...
This method should be called: forward_messages_to_server? and should check to see if we have to forward it, by a combination of checking configuration and/or checking actual behavior.
Why should I care?
Because if you are using a lot of outside processes to do stuff, then you are adding unneeded overhead forwarding this stuff to the server.
The current work around is very simple: Just add this line to the hyperstack initializer
def Hyperstack.on_server?; true; end
We did have a conversation about this a couple of years ago...now i think understand it better. Back then i upgraded to a problematic version of puma and could not work from the command line...it blocked when trying to communicate changed records through the REST channel... The work around for me was to doscinnect the console by setting:
class ReactiveRecord::Broadcast; def self.send_to_server(*args); end; end
in the hyperstack initializer. After puma was back to normal a needed another work around in there:
Hyperstack.class_eval do
def self.on_server?
Rails.const_defined?('Server') || (Rails.const_defined?('Puma') && File.basename($0).present? && File.basename($0).include?('puma'))
end
end
I had to mention puma explicitly for the whole messaging system to work correctly, maybe due way i start rails server.
I suppose this is relevant and i wanted you to know.