You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.
Due to the blocking nature of Redis#subscribe, I think it's pretty much impossible to unsubscribe from a subscription channel (except maybe from a subscription callback). Have a look at this code:
require'celluloid'require'celluloid/redis'classRedisListenerincludeCelluloidincludeCelluloid::LoggerCHANNEL="updates"definitialize(redis)@redis=redisasync.subscribeend# Subscribes to the channel on and forwards messages them via# the broker actor.defsubscribeinfo"Subscribing to Redis channel #{CHANNEL.inspect} ..."@redis.subscribe(CHANNEL)do |on|
on.messagedo |channel,msg|
info"Received message from Redis: #{msg.inspect}"Actor[:broker].forward(msg)endendenddefunsubscribeinfo"unsubscribing from Redis ..."@redis.unsubscribe(CHANNEL)endfinalizer:unsubscribeendclassBrokerincludeCelluloidincludeCelluloid::Loggerdefforward(msg)info"Forwarding message #{msg.inspect}"endendCelluloid.register_shutdownBroker.supervise_as:brokerredis=Redis.new(driver: :celluloid)RedisListener.supervise_as:redis_listener,rediswarn"sleeping in main thread"sleep
It starts fine and even prints the "sleeping in main thread" message (which it wouldn't if the call to #subscribe wasn't async. When I hit Ctrl-C to stop the program it tries to terminate the actors cleanly but fails.
I, [2014-09-24T22:43:25.555864 #80670] INFO -- : Subscribing to Redis channel "updates" ...
sleeping in main thread
^CD, [2014-09-24T22:43:28.035428 #80670] DEBUG -- : Terminating 4 actors...
E, [2014-09-24T22:43:38.036333 #80670] ERROR -- : Couldn't cleanly terminate all actors in 10 seconds!
celluloid-redis.report.rb:51:in `sleep': Interrupt
from celluloid-redis.report.rb:51:in `<main>'
What's the right way to unsubscribe and cleanly shutdown this actor?
The text was updated successfully, but these errors were encountered:
Due to the blocking nature of Redis#subscribe, I think it's pretty much impossible to unsubscribe from a subscription channel (except maybe from a subscription callback). Have a look at this code:
It starts fine and even prints the "sleeping in main thread" message (which it wouldn't if the call to #subscribe wasn't async. When I hit Ctrl-C to stop the program it tries to terminate the actors cleanly but fails.
What's the right way to unsubscribe and cleanly shutdown this actor?
The text was updated successfully, but these errors were encountered: