Class: Meeseeks::Harvester
- Inherits:
-
Object
- Object
- Meeseeks::Harvester
- Defined in:
- lib/meeseeks/harvester.rb
Instance Attribute Summary collapse
-
#cycle_count ⇒ Object
readonly
Returns the value of attribute cycle_count.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#max_batch_size ⇒ Object
readonly
Returns the value of attribute max_batch_size.
Instance Method Summary collapse
- #drain ⇒ Object
-
#initialize(queue:, http_trap:, interval: 60, max_batch_size: 100) ⇒ Harvester
constructor
A new instance of Harvester.
- #kill ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #stats ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(queue:, http_trap:, interval: 60, max_batch_size: 100) ⇒ Harvester
Returns a new instance of Harvester.
11 12 13 14 15 16 17 18 |
# File 'lib/meeseeks/harvester.rb', line 11 def initialize(queue:, http_trap:, interval: 60, max_batch_size: 100) @queue = queue @http_trap = http_trap @interval = interval @max_batch_size = max_batch_size @cycle_count = 0 @lock = Mutex.new end |
Instance Attribute Details
#cycle_count ⇒ Object (readonly)
Returns the value of attribute cycle_count.
9 10 11 |
# File 'lib/meeseeks/harvester.rb', line 9 def cycle_count @cycle_count end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
9 10 11 |
# File 'lib/meeseeks/harvester.rb', line 9 def interval @interval end |
#max_batch_size ⇒ Object (readonly)
Returns the value of attribute max_batch_size.
9 10 11 |
# File 'lib/meeseeks/harvester.rb', line 9 def max_batch_size @max_batch_size end |
Instance Method Details
#drain ⇒ Object
54 55 56 57 58 |
# File 'lib/meeseeks/harvester.rb', line 54 def drain @lock.synchronize do drain_queue_async end end |
#kill ⇒ Object
46 47 48 |
# File 'lib/meeseeks/harvester.rb', line 46 def kill @thread&.kill if @thread&.alive? end |
#running? ⇒ Boolean
50 51 52 |
# File 'lib/meeseeks/harvester.rb', line 50 def running? @thread&.alive? end |
#start ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/meeseeks/harvester.rb', line 27 def start @continue = true return if @thread&.alive? @thread = Thread.new do loop do sleep(@interval) break unless @continue @cycle_count += 1 drain end end end |
#stats ⇒ Object
20 21 22 23 24 25 |
# File 'lib/meeseeks/harvester.rb', line 20 def stats { cycle_count: @cycle_count, running: running? } end |
#stop ⇒ Object
42 43 44 |
# File 'lib/meeseeks/harvester.rb', line 42 def stop @continue = false end |