Class: Derrick::Collector
- Inherits:
-
Object
- Object
- Derrick::Collector
- Defined in:
- lib/derrick/collector.rb
Instance Method Summary collapse
- #collect_keys ⇒ Object
-
#initialize(redis, queue, progress, context) ⇒ Collector
constructor
A new instance of Collector.
- #run ⇒ Object
Constructor Details
#initialize(redis, queue, progress, context) ⇒ Collector
Returns a new instance of Collector.
3 4 5 6 7 8 |
# File 'lib/derrick/collector.rb', line 3 def initialize(redis, queue, progress, context) @redis = redis @queue = queue @progress = progress @context = context end |
Instance Method Details
#collect_keys ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/derrick/collector.rb', line 15 def collect_keys cursor = '0' loop do cursor, keys = @redis.scan(cursor, count: @context.batch_size) @queue.push(keys) @progress.increment_collected(keys.size) return if cursor == '0' end end |
#run ⇒ Object
10 11 12 13 |
# File 'lib/derrick/collector.rb', line 10 def run collect_keys @context.concurrency.times { @queue.push(:stop) } end |