Created
August 20, 2013 06:49
-
-
Save StephanieSunshine/6277870 to your computer and use it in GitHub Desktop.
How do I get celluloid-redis to work within a class?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'celluloid' | |
require 'celluloid/redis' | |
require 'sucker_punch' | |
class BWorker | |
include SuckerPunch::Job | |
include Celluloid::Redis | |
include Redis | |
def perform | |
trap(:INT) { puts; exit } | |
redis = Redis.new(:driver => :celluloid) | |
redis.subscribe(:one, :two) do |on| | |
on.subscribe do |channel, subscriptions| | |
puts "Subscribed to ##{channel} (#{subscriptions} subscriptions)" | |
end | |
on.message do |channel, message| | |
puts "##{channel}: #{message}" | |
redis.unsubscribe if message == "exit" | |
end | |
on.unsubscribe do |channel, subscriptions| | |
puts "Unsubscribed from ##{channel} (#{subscriptions} subscriptions)" | |
end | |
end | |
end | |
end | |
#Test.run | |
BWorker.new.async.perform | |
puts "test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test | |
E, [2013-08-19T23:45:58.653389 #25454] ERROR -- : BWorker crashed! | |
NoMethodError: undefined method `new' for Celluloid::Redis:Module | |
./celluloid-redis-test.rb:18:in `perform' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in `public_send' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in `dispatch' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:67:in `dispatch' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/actor.rb:326:in `block in handle_message' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/tasks.rb:42:in `block in initialize' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/tasks/task_fiber.rb:11:in `block in create' | |
D, [2013-08-19T23:45:58.653665 #25454] DEBUG -- : Celluloid::PoolManager: async call `perform` aborted! | |
NoMethodError: undefined method `new' for Celluloid::Redis:Module | |
./celluloid-redis-test.rb:18:in `perform' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in `public_send' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in `dispatch' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:67:in `dispatch' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/actor.rb:326:in `block in handle_message' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/tasks.rb:42:in `block in initialize' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/tasks/task_fiber.rb:11:in `block in create' | |
(celluloid):0:in `remote procedure call' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:95:in `value' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/proxies/sync_proxy.rb:28:in `method_missing' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/legacy.rb:14:in `method_missing' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/proxies/actor_proxy.rb:25:in `_send_' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/pool_manager.rb:41:in `_send_' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/pool_manager.rb:122:in `method_missing' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in `public_send' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in `dispatch' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:125:in `dispatch' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/actor.rb:326:in `block in handle_message' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/tasks.rb:42:in `block in initialize' | |
/var/lib/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/tasks/task_fiber.rb:11:in `block in create' | |
D, [2013-08-19T23:45:58.653892 #25454] DEBUG -- : Terminating 3 actors... | |
D, [2013-08-19T23:45:58.655712 #25454] DEBUG -- : Shutdown completed cleanly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment