Class: Wurk::BatchSet
- Inherits:
-
Object
- Object
- Wurk::BatchSet
- Includes:
- Enumerable
- Defined in:
- lib/wurk/batch_set.rb
Overview
Discovery API over the global batches sorted set. size, each (yields
Status), scan_tags(tag) for tag-indexed lookup.
Spec: docs/target/sidekiq-pro.md §2.7.
Direct Known Subclasses
Constant Summary collapse
- PAGE_SIZE =
100
Instance Method Summary collapse
-
#each ⇒ Object
Newest-first iteration of every batch indexed in the set.
-
#initialize(key: 'batches') ⇒ BatchSet
constructor
A new instance of BatchSet.
-
#scan_tags(tag, &block) ⇒ Object
Yields each BID indexed under the given tag (set at
tags:<tag>). - #size ⇒ Object
Constructor Details
#initialize(key: 'batches') ⇒ BatchSet
Returns a new instance of BatchSet.
15 16 17 |
# File 'lib/wurk/batch_set.rb', line 15 def initialize(key: 'batches') @key = key end |
Instance Method Details
#each ⇒ Object
Newest-first iteration of every batch indexed in the set. Yields
Wurk::Batch::Status instances — they HGETALL on construction so
the caller pays one Redis round-trip per batch.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wurk/batch_set.rb', line 26 def each return enum_for(:each) unless block_given? page = 0 loop do start = page * PAGE_SIZE stop = start + PAGE_SIZE - 1 bids = Wurk.redis { |conn| conn.call('ZRANGE', @key, start, stop, 'REV') } bids.each { |bid| yield Wurk::Batch::Status.new(bid) } break if bids.size < PAGE_SIZE page += 1 end end |
#scan_tags(tag, &block) ⇒ Object
Yields each BID indexed under the given tag (set at tags:<tag>).
No JSON parsing; cheap iteration. Caller wraps in Status.new(bid)
if it needs full state.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/wurk/batch_set.rb', line 44 def (tag, &block) return enum_for(:scan_tags, tag) unless block_given? cursor = '0' Wurk.redis do |conn| loop do cursor, members = conn.call('SSCAN', "tags:#{tag}", cursor, 'COUNT', PAGE_SIZE) members.each(&block) break if cursor == '0' end end end |