Class: Sidekiq::ProfileSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sidekiq/api.rb

Instance Method Summary collapse

Constructor Details

#initializeProfileSet

This is a point in time/snapshot API, you’ll need to instantiate a new instance if you want to fetch newer records.



1341
1342
1343
1344
1345
1346
1347
1348
# File 'lib/sidekiq/api.rb', line 1341

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



1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
# File 'lib/sidekiq/api.rb', line 1354

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

#sizeObject



1350
1351
1352
# File 'lib/sidekiq/api.rb', line 1350

def size
  @records.size
end