Class: Wurk::ProfileSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/wurk/profile_set.rb

Overview

Read-only view over stored job profiles (Sidekiq 8.0+ data API, spec §19.8). ‘ProfileSet` enumerates the `profiles` ZSET, purging expired members first; `ProfileRecord` wraps one `<token>-<jid>` HASH.

Instance Method Summary collapse

Constructor Details

#initializeProfileSet

Snapshot the (non-expired) member keys at construction. ZREMRANGEBYSCORE drops members whose expiry score has passed before we read the rest.



15
16
17
18
19
20
# File 'lib/wurk/profile_set.rb', line 15

def initialize
  @keys = Wurk.redis do |conn|
    conn.call('ZREMRANGEBYSCORE', Keys::PROFILES, '-inf', "(#{::Time.now.to_i}")
    conn.call('ZRANGE', Keys::PROFILES, 0, -1)
  end
end

Instance Method Details

#eachObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wurk/profile_set.rb', line 24

def each
  return enum_for(:each) unless block_given?

  Wurk.redis do |conn|
    @keys.each do |key|
      raw = conn.call('HGETALL', key)
      hash = raw.is_a?(Hash) ? raw : raw.each_slice(2).to_h
      yield ProfileRecord.new(hash) unless hash.empty?
    end
  end
end

#sizeObject



22
# File 'lib/wurk/profile_set.rb', line 22

def size = @keys.size