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. %w[jid type token size elapsed started_at].freeze
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
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/wurk/profile_set.rb', line 29 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 do |values| hash = METADATA_FIELDS.zip(Array(values)).to_h yield ProfileRecord.new(hash) unless hash['jid'].nil? end end |
#size ⇒ Object
22 |
# File 'lib/wurk/profile_set.rb', line 22 def size = @keys.size |