Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a broadcast? #38

Open
nathanpalmer opened this issue Oct 14, 2013 · 2 comments
Open

Is there a broadcast? #38

nathanpalmer opened this issue Oct 14, 2013 · 2 comments

Comments

@nathanpalmer
Copy link

I'm looking for a shortcut to transmit_to_all. Essentially a way to broadcast messages to anyone watching. The usecase I'm in is transmitting progress for jobs but I'll have several watchers on it.

Technically I'm getting stale watchers and the jobs are getting put into no-where. I'm trying to work that out (possibly an issue with ActionController::Live not ever disconnecting on a refresh.

@tdg5
Copy link
Member

tdg5 commented Dec 13, 2013

Hey Nathan,
Sorry no one has responded sooner, but hopefully I can help or at least clarify what you're looking for. Were you ever able to resolve your issue with stale watchers?

I'm inclined to believe I'm misunderstanding your use-case (especially since you literally reference transmit_to_all), but I'll go for broke and start with the dumb answer: Are you familiar with Beaneater::Pool#transmit_to_all? It seems to me to be what you're describing. There's also Beaneater::Pool#transmit_until_res if you prefer to broadcast until a response is received.

If you're already familiar with these methods, could you help me better understand more specifically what you're looking for?

@nathanpalmer
Copy link
Author

I never did get a resolution to it. I was asking if there was a built-in way to broadcast messages to every receiver on a tube. I was familiar with transmit_to_all but that seemed more of a raw command. I ended up writing a portion of code on the tube that looked like this.

module Beaneater
  class Tube < PoolCommand
    def broadcast(body, options={})
      safe_use do
        options = { :pri => config.default_put_pri, :delay => config.default_put_delay,
                    :ttr => config.default_put_ttr }.merge(options)
        cmd_options = "#{options[:pri]} #{options[:delay]} #{options[:ttr]} #{body.bytesize}"
        transmit_to_all("put #{cmd_options}\r\n#{body}")
      end
    end
  end
end

However, I have 4 "currently_watching" and I need the message to go to all of them. (The previous 3 watchers are because the pool isn't getting closed properly.) I'm getting very sporadic behavior.. sometimes the message comes through and sometimes it doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants