Class: BgResults::Batch
- Inherits:
-
Object
- Object
- BgResults::Batch
- Defined in:
- lib/bg_results/batch.rb
Constant Summary collapse
- RESULT_TTL =
1 day
86400
Instance Method Summary collapse
- #clear_results! ⇒ Object
-
#initialize(bid) ⇒ Batch
constructor
A new instance of Batch.
- #results ⇒ Object
- #results_each ⇒ Object
- #results_in_batches ⇒ Object
- #set_results_expire(exp = RESULT_TTL) ⇒ Object
Constructor Details
#initialize(bid) ⇒ Batch
Returns a new instance of Batch.
4 5 6 7 |
# File 'lib/bg_results/batch.rb', line 4 def initialize bid @bid = bid @key = "RESULTS-#{@bid}" end |
Instance Method Details
#clear_results! ⇒ Object
46 47 48 49 50 |
# File 'lib/bg_results/batch.rb', line 46 def clear_results! BgResults.redis do |conn| conn.del @key end end |
#results ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/bg_results/batch.rb', line 9 def results data, _ = BgResults.redis do |conn| conn.multi do conn.hgetall @key conn.expire @key, RESULT_TTL end end parse_results data end |
#results_each ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/bg_results/batch.rb', line 31 def results_each return unless block_given? results_in_batches do |batch| batch.each do |jid, res| yield jid, res end end end |
#results_in_batches ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bg_results/batch.rb', line 19 def results_in_batches count = 100 cursor = 0 loop do cursor, data = scan cursor, count data = parse_results data.to_h yield data break if cursor == 0 end set_results_expire end |