Class: Reqless::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/reqless.rb

Overview

The client for interacting with Reqless

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  default_options = {:ensure_minimum_version => true}
  options = default_options.merge(options)

  should_ensure_minimum_redis_version = options.delete(:ensure_minimum_version)
  # This is the redis instance we're connected to. Use connect so REDIS_URL
  # will be honored
  @redis   = options[:redis] || Redis.new(options)
  @options = 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

#_reqlessObject (readonly)

Returns the value of attribute _reqless.



226
227
228
# File 'lib/reqless.rb', line 226

def _reqless
  @_reqless
end

#configObject (readonly)

Returns the value of attribute config.



226
227
228
# File 'lib/reqless.rb', line 226

def config
  @config
end

#jobsObject (readonly)

Returns the value of attribute jobs.



226
227
228
# File 'lib/reqless.rb', line 226

def jobs
  @jobs
end

#queue_patternsObject (readonly)

Returns the value of attribute queue_patterns.



226
227
228
# File 'lib/reqless.rb', line 226

def queue_patterns
  @queue_patterns
end

#queuesObject (readonly)

Returns the value of attribute queues.



226
227
228
# File 'lib/reqless.rb', line 226

def queues
  @queues
end

#redisObject (readonly)

Returns the value of attribute redis.



226
227
228
# File 'lib/reqless.rb', line 226

def redis
  @redis
end

#throttlesObject (readonly)

Returns the value of attribute throttles.



226
227
228
# File 'lib/reqless.rb', line 226

def throttles
  @throttles
end

#worker_nameObject

Returns the value of attribute worker_name.



227
228
229
# File 'lib/reqless.rb', line 227

def worker_name
  @worker_name
end

#workersObject (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

#eventsObject



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

#hashObject



294
295
296
# File 'lib/reqless.rb', line 294

def hash
  self.class.hash ^ redis.id.hash
end

#inspectObject



250
251
252
# File 'lib/reqless.rb', line 250

def inspect
  "<Reqless::Client #{@options} >"
end

#new_redis_connectionObject



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 tags(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