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
- #each(&block) ⇒ Object
- #find_job(jid) ⇒ Object
-
#initialize(name = "default") ⇒ Queue
constructor
A new instance of Queue.
- #latency ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(name = "default") ⇒ Queue
Returns a new instance of Queue.
102 103 104 105 |
# File 'lib/sidekiq/api.rb', line 102 def initialize(name="default") @name = name @rname = "queue:#{name}" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
100 101 102 |
# File 'lib/sidekiq/api.rb', line 100 def name @name end |
Class Method Details
Instance Method Details
#clear ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/sidekiq/api.rb', line 139 def clear Sidekiq.redis do |conn| conn.multi do conn.del(@rname) conn.srem("queues", name) end end end |
#each(&block) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/sidekiq/api.rb', line 119 def each(&block) page = 0 page_size = 50 loop do entries = Sidekiq.redis do |conn| conn.lrange @rname, page * page_size, (page * page_size) + page_size - 1 end break if entries.empty? page += 1 entries.each do |entry| block.call Job.new(entry, @name) end end end |
#find_job(jid) ⇒ Object
135 136 137 |
# File 'lib/sidekiq/api.rb', line 135 def find_job(jid) self.detect { |j| j.jid == jid } end |