Class: Qless::ClientEvents
- Inherits:
-
Object
- Object
- Qless::ClientEvents
- Defined in:
- lib/qless.rb
Overview
A class for interacting with events. Not meant to be instantiated directly, it’s accessed through Client#events
Constant Summary collapse
- EVENTS =
%w{canceled completed failed popped stalled put track untrack}
Instance Method Summary collapse
-
#initialize(redis) ⇒ ClientEvents
constructor
A new instance of ClientEvents.
- #listen {|_self| ... } ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(redis) ⇒ ClientEvents
Returns a new instance of ClientEvents.
148 149 150 151 |
# File 'lib/qless.rb', line 148 def initialize(redis) @redis = redis @actions = {} end |
Instance Method Details
#listen {|_self| ... } ⇒ Object
153 154 155 156 157 158 159 160 161 162 |
# File 'lib/qless.rb', line 153 def listen yield(self) if block_given? channels = EVENTS.map { |event| "ql:#{event}" } @redis.subscribe(channels) do |on| on. do |channel, | callback = @actions[channel.sub('ql:', '').to_sym] callback.call() unless callback.nil? end end end |
#stop ⇒ Object
164 165 166 |
# File 'lib/qless.rb', line 164 def stop @redis.unsubscribe end |