Class: Sidekiq::Queue
Overview
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.all ⇒ Object
Return all known queues within Redis.
Instance Method Summary collapse
-
#as_json(options = nil) ⇒ Object
:nodoc:.
- #clear ⇒ Object (also: #💣)
- #each ⇒ Object
-
#find_job(jid) ⇒ Object
Find the job with the given JID within this queue.
-
#initialize(name = "default") ⇒ Queue
constructor
A new instance of Queue.
-
#latency ⇒ Object
Calculates this queue's latency, the difference in seconds since the oldest job in the queue was enqueued.
-
#paused? ⇒ Boolean
Sidekiq Pro overrides this.
- #size ⇒ Object
Constructor Details
#initialize(name = "default") ⇒ Queue
Returns a new instance of Queue.
228 229 230 231 |
# File 'lib/sidekiq/api.rb', line 228 def initialize(name = "default") @name = name.to_s @rname = "queue:#{name}" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
226 227 228 |
# File 'lib/sidekiq/api.rb', line 226 def name @name end |
Class Method Details
Instance Method Details
#as_json(options = nil) ⇒ Object
:nodoc:
298 299 300 |
# File 'lib/sidekiq/api.rb', line 298 def as_json( = nil) # :nodoc: {name: name} # 5336 end |
#clear ⇒ Object Also known as: 💣
288 289 290 291 292 293 294 295 |
# File 'lib/sidekiq/api.rb', line 288 def clear Sidekiq.redis do |conn| conn.multi do |transaction| transaction.unlink(@rname) transaction.srem("queues", name) end end end |
#each ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/sidekiq/api.rb', line 258 def each initial_size = size deleted_size = 0 page = 0 page_size = 50 loop do range_start = page * page_size - deleted_size range_end = range_start + page_size - 1 entries = Sidekiq.redis { |conn| conn.lrange @rname, range_start, range_end } break if entries.empty? page += 1 entries.each do |entry| yield JobRecord.new(entry, @name) end deleted_size = initial_size - size end end |
#find_job(jid) ⇒ Object
Find the job with the given JID within this queue.
This is a slow, inefficient operation. Do not use under normal conditions.
284 285 286 |
# File 'lib/sidekiq/api.rb', line 284 def find_job(jid) detect { |j| j.jid == jid } end |
#latency ⇒ Object
Calculates this queue's latency, the difference in seconds since the oldest job in the queue was enqueued.
247 248 249 250 251 252 253 254 255 256 |
# File 'lib/sidekiq/api.rb', line 247 def latency entry = Sidekiq.redis { |conn| conn.lrange(@rname, -1, -1) }.first return 0 unless entry job = Sidekiq.load_json(entry) now = Time.now.to_f thence = job["enqueued_at"] || now now - thence end |
#paused? ⇒ Boolean
Sidekiq Pro overrides this
238 239 240 |
# File 'lib/sidekiq/api.rb', line 238 def paused? false end |