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.
Constant Summary collapse
- METADATA_FIELDS =
HMGET of the metadata fields only, pipelined into one round-trip: HGETALL would also pull each profile's
datafield — the multi-MB gzipped blob — through Redis for every list render. Upstream's order, which ProfileRecord.new reads positionally. %w[started_at jid type token size elapsed].freeze
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize ⇒ ProfileSet
constructor
Snapshot the (non-expired) member keys at construction, newest first.
- #size ⇒ Object
Constructor Details
#initialize ⇒ ProfileSet
Snapshot the (non-expired) member keys at construction, newest first. ZREMRANGEBYSCORE drops members whose expiry score has passed.
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_f.to_s) conn.call('ZRANGE', Keys::PROFILES, '+inf', 0, 'BYSCORE', 'REV') end end |
Instance Method Details
#each ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wurk/profile_set.rb', line 30 def each return enum_for(:each) unless block_given? rows = Wurk.redis do |conn| conn.pipelined do |pipe| @keys.each { |key| pipe.call('HMGET', key, *METADATA_FIELDS) } end end rows.each { |values| yield ProfileRecord.new(values) unless values.nil? || values[1].nil? } end |
#size ⇒ Object
22 |
# File 'lib/wurk/profile_set.rb', line 22 def size = @keys.size |