Class: Qless::Client
- Inherits:
-
Object
- Object
- Qless::Client
- Defined in:
- lib/qless.rb
Overview
The client for interacting with Qless
Instance Attribute Summary collapse
-
#_qless ⇒ Object
readonly
Lua script.
-
#config ⇒ Object
readonly
Lua script.
-
#jobs ⇒ Object
readonly
Lua script.
-
#queues ⇒ Object
readonly
Lua script.
-
#redis ⇒ Object
readonly
Lua script.
-
#worker_name ⇒ Object
Returns the value of attribute worker_name.
-
#workers ⇒ Object
readonly
Lua script.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #bulk_cancel(jids) ⇒ Object
- #call(command, *argv) ⇒ Object
- #deregister_workers(*worker_names) ⇒ Object
- #events ⇒ Object
- #hash ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
-
#new_redis_connection ⇒ Object
redis version < 3.0.7.
- #tags(offset = 0, count = 100) ⇒ Object
- #track(jid) ⇒ Object
- #untrack(jid) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/qless.rb', line 175 def initialize( = {}) # This is the redis instance we're connected to. Use connect so REDIS_URL # will be honored @redis = [:redis] || Redis.connect() @options = assert_minimum_redis_version('2.5.5') @config = Config.new(self) @_qless = Qless::LuaScript.new('qless', @redis) @jobs = ClientJobs.new(self) @queues = ClientQueues.new(self) @workers = ClientWorkers.new(self) @worker_name = [Socket.gethostname, Process.pid.to_s].join('-') end |
Instance Attribute Details
#_qless ⇒ Object (readonly)
Lua script
172 173 174 |
# File 'lib/qless.rb', line 172 def _qless @_qless end |
#config ⇒ Object (readonly)
Lua script
172 173 174 |
# File 'lib/qless.rb', line 172 def config @config end |
#jobs ⇒ Object (readonly)
Lua script
172 173 174 |
# File 'lib/qless.rb', line 172 def jobs @jobs end |
#queues ⇒ Object (readonly)
Lua script
172 173 174 |
# File 'lib/qless.rb', line 172 def queues @queues end |
#redis ⇒ Object (readonly)
Lua script
172 173 174 |
# File 'lib/qless.rb', line 172 def redis @redis end |
#worker_name ⇒ Object
Returns the value of attribute worker_name.
173 174 175 |
# File 'lib/qless.rb', line 173 def worker_name @worker_name end |
#workers ⇒ Object (readonly)
Lua script
172 173 174 |
# File 'lib/qless.rb', line 172 def workers @workers end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
235 236 237 |
# File 'lib/qless.rb', line 235 def ==(other) self.class == other.class && redis.id == other.redis.id end |
#bulk_cancel(jids) ⇒ Object
221 222 223 |
# File 'lib/qless.rb', line 221 def bulk_cancel(jids) call('cancel', jids) end |
#call(command, *argv) ⇒ Object
201 202 203 |
# File 'lib/qless.rb', line 201 def call(command, *argv) @_qless.call(command, Time.now.to_f, *argv) end |
#deregister_workers(*worker_names) ⇒ Object
217 218 219 |
# File 'lib/qless.rb', line 217 def deregister_workers(*worker_names) call('worker.deregister', *worker_names) end |
#events ⇒ Object
194 195 196 197 198 199 |
# File 'lib/qless.rb', line 194 def events # Events needs its own redis instance of the same configuration, because # once it's subscribed, we can only use pub-sub-like commands. This way, # we still have access to the client in the normal case @events ||= ClientEvents.new(Redis.connect(@options)) end |
#hash ⇒ Object
240 241 242 |
# File 'lib/qless.rb', line 240 def hash self.class.hash ^ redis.id.hash end |
#inspect ⇒ Object
190 191 192 |
# File 'lib/qless.rb', line 190 def inspect "<Qless::Client #{@options} >" end |
#new_redis_connection ⇒ Object
redis version < 3.0.7
230 231 232 |
# File 'lib/qless.rb', line 230 def new_redis_connection redis.dup end |
#tags(offset = 0, count = 100) ⇒ Object
213 214 215 |
# File 'lib/qless.rb', line 213 def (offset = 0, count = 100) JSON.parse(call('tag', 'top', offset, count)) end |
#track(jid) ⇒ Object
205 206 207 |
# File 'lib/qless.rb', line 205 def track(jid) call('track', 'track', jid) end |
#untrack(jid) ⇒ Object
209 210 211 |
# File 'lib/qless.rb', line 209 def untrack(jid) call('track', 'untrack', jid) end |