Class: Sidekiq::Queue
Overview
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object (also: #💣)
- #each ⇒ Object
- #find_job(jid) ⇒ Object
-
#initialize(name = "default") ⇒ Queue
constructor
A new instance of Queue.
- #latency ⇒ Object
-
#paused? ⇒ Boolean
Sidekiq Pro overrides this.
- #size ⇒ Object
Constructor Details
#initialize(name = "default") ⇒ Queue
Returns a new instance of Queue.
200 201 202 203 |
# File 'lib/sidekiq/api.rb', line 200 def initialize(name="default") @name = name @rname = "queue:#{name}" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
198 199 200 |
# File 'lib/sidekiq/api.rb', line 198 def name @name end |
Class Method Details
Instance Method Details
#clear ⇒ Object Also known as: 💣
247 248 249 250 251 252 253 254 |
# File 'lib/sidekiq/api.rb', line 247 def clear Sidekiq.redis do |conn| conn.multi do conn.del(@rname) conn.srem("queues".freeze, name) end end end |
#each ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/sidekiq/api.rb', line 222 def each initial_size = size deleted_size = 0 page = 0 page_size = 50 loop do range_start = page * page_size - deleted_size range_end = page * page_size - deleted_size + (page_size - 1) entries = Sidekiq.redis do |conn| conn.lrange @rname, range_start, range_end end break if entries.empty? page += 1 entries.each do |entry| yield Job.new(entry, @name) end deleted_size = initial_size - size end end |
#find_job(jid) ⇒ Object
243 244 245 |
# File 'lib/sidekiq/api.rb', line 243 def find_job(jid) detect { |j| j.jid == jid } end |
#latency ⇒ Object
214 215 216 217 218 219 220 |
# File 'lib/sidekiq/api.rb', line 214 def latency entry = Sidekiq.redis do |conn| conn.lrange(@rname, -1, -1) end.first return 0 unless entry Time.now.to_f - Sidekiq.load_json(entry)['enqueued_at'] end |
#paused? ⇒ Boolean
Sidekiq Pro overrides this
210 211 212 |
# File 'lib/sidekiq/api.rb', line 210 def paused? false end |