Class: Qless::Client

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

Overview

The client for interacting with Qless

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#_qlessObject (readonly)

Lua script



172
173
174
# File 'lib/qless.rb', line 172

def _qless
  @_qless
end

#configObject (readonly)

Lua script



172
173
174
# File 'lib/qless.rb', line 172

def config
  @config
end

#jobsObject (readonly)

Lua script



172
173
174
# File 'lib/qless.rb', line 172

def jobs
  @jobs
end

#queuesObject (readonly)

Lua script



172
173
174
# File 'lib/qless.rb', line 172

def queues
  @queues
end

#redisObject (readonly)

Lua script



172
173
174
# File 'lib/qless.rb', line 172

def redis
  @redis
end

#worker_nameObject

Returns the value of attribute worker_name.



173
174
175
# File 'lib/qless.rb', line 173

def worker_name
  @worker_name
end

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

#eventsObject



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

#hashObject



240
241
242
# File 'lib/qless.rb', line 240

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

#inspectObject



190
191
192
# File 'lib/qless.rb', line 190

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

#new_redis_connectionObject

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