Class: Sidekiq::ProfileSet
- Inherits:
-
Object
- Object
- Sidekiq::ProfileSet
- Includes:
- Enumerable
- Defined in:
- lib/sidekiq/api.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize ⇒ ProfileSet
constructor
This is a point in time/snapshot API, you’ll need to instantiate a new instance if you want to fetch newer records.
- #size ⇒ Object
Constructor Details
#initialize ⇒ ProfileSet
This is a point in time/snapshot API, you’ll need to instantiate a new instance if you want to fetch newer records.
1221 1222 1223 1224 1225 1226 1227 1228 |
# File 'lib/sidekiq/api.rb', line 1221 def initialize @records = Sidekiq.redis do |c| # This throws away expired profiles c.zremrangebyscore("profiles", "-inf", Time.now.to_f.to_s) # retreive records, newest to oldest c.zrange("profiles", "+inf", 0, "byscore", "rev") end end |
Instance Method Details
#each(&block) ⇒ Object
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 |
# File 'lib/sidekiq/api.rb', line 1234 def each(&block) fetch_keys = %w[started_at jid type token size elapsed].freeze arrays = Sidekiq.redis do |c| c.pipelined do |p| @records.each do |key| p.hmget(key, *fetch_keys) end end end arrays.compact.map { |arr| ProfileRecord.new(arr) }.each(&block) end |
#size ⇒ Object
1230 1231 1232 |
# File 'lib/sidekiq/api.rb', line 1230 def size @records.size end |