Class: Qless::ClientEvents
- Inherits:
-
Object
- Object
- Qless::ClientEvents
- Defined in:
- lib/qless.rb
Instance Method Summary collapse
- #canceled(&block) ⇒ Object
- #completed(&block) ⇒ Object
- #failed(&block) ⇒ Object
-
#initialize(redis) ⇒ ClientEvents
constructor
A new instance of ClientEvents.
- #listen {|_self| ... } ⇒ Object
- #popped(&block) ⇒ Object
- #put(&block) ⇒ Object
- #stalled(&block) ⇒ Object
- #stop ⇒ Object
- #track(&block) ⇒ Object
- #untrack(&block) ⇒ Object
Constructor Details
#initialize(redis) ⇒ ClientEvents
Returns a new instance of ClientEvents.
114 115 116 117 |
# File 'lib/qless.rb', line 114 def initialize(redis) @redis = redis @actions = Hash.new() end |
Instance Method Details
#canceled(&block) ⇒ Object
119 |
# File 'lib/qless.rb', line 119 def canceled(&block) ; @actions[:canceled ] = block; end |
#completed(&block) ⇒ Object
120 |
# File 'lib/qless.rb', line 120 def completed(&block); @actions[:completed] = block; end |
#failed(&block) ⇒ Object
121 |
# File 'lib/qless.rb', line 121 def failed(&block) ; @actions[:failed ] = block; end |
#listen {|_self| ... } ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/qless.rb', line 128 def listen yield(self) if block_given? @redis.subscribe(:canceled, :completed, :failed, :popped, :stalled, :put, :track, :untrack) do |on| on. do |channel, | callback = @actions[channel.to_sym] if not callback.nil? callback.call() end end end end |
#popped(&block) ⇒ Object
122 |
# File 'lib/qless.rb', line 122 def popped(&block) ; @actions[:popped ] = block; end |
#put(&block) ⇒ Object
124 |
# File 'lib/qless.rb', line 124 def put(&block) ; @actions[:put ] = block; end |
#stalled(&block) ⇒ Object
123 |
# File 'lib/qless.rb', line 123 def stalled(&block) ; @actions[:stalled ] = block; end |
#stop ⇒ Object
140 141 142 |
# File 'lib/qless.rb', line 140 def stop @redis.unsubscribe end |
#track(&block) ⇒ Object
125 |
# File 'lib/qless.rb', line 125 def track(&block) ; @actions[:track ] = block; end |
#untrack(&block) ⇒ Object
126 |
# File 'lib/qless.rb', line 126 def untrack(&block) ; @actions[:untrack ] = block; end |