Class: Lowkiq::Schedulers::Seq

Inherits:
Object
  • Object
show all
Defined in:
lib/lowkiq/schedulers/seq.rb

Instance Method Summary collapse

Constructor Details

#initialize(wait) ⇒ Seq

Returns a new instance of Seq.



4
5
6
# File 'lib/lowkiq/schedulers/seq.rb', line 4

def initialize(wait)
  @wait = wait
end

Instance Method Details

#build_job(shard_handlers) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lowkiq/schedulers/seq.rb', line 8

def build_job(shard_handlers)
  shard_enumerator = shard_handlers.cycle
  processed = []

  lambda do
    if processed.length == shard_handlers.length
      all_failed = processed.all? { |ok| !ok }
      processed.clear
      if all_failed
        @wait.call
        return
      end
    end

    shard_handler = shard_enumerator.next
    processed << shard_handler.process
  end
end