Skip to content

Instantly share code, notes, and snippets.

@pricees
Created November 12, 2012 21:52
Show Gist options
  • Save pricees/4062179 to your computer and use it in GitHub Desktop.
Save pricees/4062179 to your computer and use it in GitHub Desktop.
redis pubsub subscriber instance
Subscriber.new(channel) do |_, m|
begin
hsh = JSON.parse(m)
logger = ENV["RACK_ENV"] == "development" ? $stdout : $stderr
klass = hsh["class"]
method = hsh["method"]
args = hsh["args"]
if Object.const_defined?(klass)
obj = Object.const_get(klass)
else
logger.write "No object #{klass}"
end
if obj.respond_to?(method)
res = obj.send(method.to_sym, *args)
logger.write res
else
logger.write "No method ##{method} for object #{klass}"
end
rescue Exception => blasto
logger.puts blasto
ensure
logger.flush
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment