Class: Reqless::Client
- Inherits:
-
Object
- Object
- Reqless::Client
- Defined in:
- lib/reqless.rb
Overview
The client for interacting with Reqless
Instance Attribute Summary collapse
-
#_reqless ⇒ Object
readonly
Returns the value of attribute _reqless.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#jobs ⇒ Object
readonly
Returns the value of attribute jobs.
-
#queue_patterns ⇒ Object
readonly
Returns the value of attribute queue_patterns.
-
#queues ⇒ Object
readonly
Returns the value of attribute queues.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
-
#throttles ⇒ Object
readonly
Returns the value of attribute throttles.
-
#worker_name ⇒ Object
Returns the value of attribute worker_name.
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
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
- #tags(offset = 0, count = 100) ⇒ Object
- #track(jid) ⇒ Object
- #untrack(jid) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/reqless.rb', line 229 def initialize( = {}) = {:ensure_minimum_version => true} = .merge() should_ensure_minimum_redis_version = .delete(:ensure_minimum_version) # This is the redis instance we're connected to. Use connect so REDIS_URL # will be honored @redis = [:redis] || Redis.new() @options = assert_minimum_redis_version('2.5.5') if should_ensure_minimum_redis_version @config = Config.new(self) @_reqless = Reqless::LuaScript.new('reqless', @redis, :on_reload_callback => @options[:on_lua_script_reload_callback]) @jobs = ClientJobs.new(self) @queues = ClientQueues.new(self) @throttles = ClientThrottles.new(self) @queue_patterns = ClientQueuePatterns.new(self) @workers = ClientWorkers.new(self) @worker_name = [Socket.gethostname, Process.pid.to_s].join('-') end |
Instance Attribute Details
#_reqless ⇒ Object (readonly)
Returns the value of attribute _reqless.
226 227 228 |
# File 'lib/reqless.rb', line 226 def _reqless @_reqless end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
226 227 228 |
# File 'lib/reqless.rb', line 226 def config @config end |
#jobs ⇒ Object (readonly)
Returns the value of attribute jobs.
226 227 228 |
# File 'lib/reqless.rb', line 226 def jobs @jobs end |
#queue_patterns ⇒ Object (readonly)
Returns the value of attribute queue_patterns.
226 227 228 |
# File 'lib/reqless.rb', line 226 def queue_patterns @queue_patterns end |
#queues ⇒ Object (readonly)
Returns the value of attribute queues.
226 227 228 |
# File 'lib/reqless.rb', line 226 def queues @queues end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
226 227 228 |
# File 'lib/reqless.rb', line 226 def redis @redis end |
#throttles ⇒ Object (readonly)
Returns the value of attribute throttles.
226 227 228 |
# File 'lib/reqless.rb', line 226 def throttles @throttles end |
#worker_name ⇒ Object
Returns the value of attribute worker_name.
227 228 229 |
# File 'lib/reqless.rb', line 227 def worker_name @worker_name end |
#workers ⇒ Object (readonly)
Returns the value of attribute workers.
226 227 228 |
# File 'lib/reqless.rb', line 226 def workers @workers end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
289 290 291 |
# File 'lib/reqless.rb', line 289 def ==(other) self.class == other.class && redis.id == other.redis.id end |
#bulk_cancel(jids) ⇒ Object
281 282 283 |
# File 'lib/reqless.rb', line 281 def bulk_cancel(jids) call('job.cancel', jids) end |
#call(command, *argv) ⇒ Object
261 262 263 |
# File 'lib/reqless.rb', line 261 def call(command, *argv) @_reqless.call(command, Time.now.to_f, *argv) end |
#deregister_workers(*worker_names) ⇒ Object
277 278 279 |
# File 'lib/reqless.rb', line 277 def deregister_workers(*worker_names) call('worker.forget', *worker_names) end |
#events ⇒ Object
254 255 256 257 258 259 |
# File 'lib/reqless.rb', line 254 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.new(@options)) end |
#hash ⇒ Object
294 295 296 |
# File 'lib/reqless.rb', line 294 def hash self.class.hash ^ redis.id.hash end |
#inspect ⇒ Object
250 251 252 |
# File 'lib/reqless.rb', line 250 def inspect "<Reqless::Client #{@options} >" end |
#new_redis_connection ⇒ Object
285 286 287 |
# File 'lib/reqless.rb', line 285 def new_redis_connection @redis.dup end |
#tags(offset = 0, count = 100) ⇒ Object
273 274 275 |
# File 'lib/reqless.rb', line 273 def (offset = 0, count = 100) JSON.parse(call('tags.top', offset, count)) end |
#track(jid) ⇒ Object
265 266 267 |
# File 'lib/reqless.rb', line 265 def track(jid) call('job.track', jid) end |
#untrack(jid) ⇒ Object
269 270 271 |
# File 'lib/reqless.rb', line 269 def untrack(jid) call('job.untrack', jid) end |