Class: Wurk::ProfileSet
- Inherits:
-
Object
- Object
- Wurk::ProfileSet
- 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
- #each ⇒ Object
-
#initialize ⇒ ProfileSet
constructor
Snapshot the (non-expired) member keys at construction.
- #size ⇒ Object
Constructor Details
#initialize ⇒ ProfileSet
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
#each ⇒ Object
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 |
#size ⇒ Object
22 |
# File 'lib/wurk/profile_set.rb', line 22 def size = @keys.size |