Module: Jober::QueueBatchFeature::InstanceMethods

Defined in:
lib/jober/queue_batch.rb

Instance Method Summary collapse

Instance Method Details

#execute_batch(batch) ⇒ Object



42
43
44
45
46
47
# File 'lib/jober/queue_batch.rb', line 42

def execute_batch(batch)
  perform(batch)
rescue Object => ex
  reschedule_batch(batch)
  exception(ex)
end

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/jober/queue_batch.rb', line 18

def run
  cnt = 0
  batch = []
  while args = pop
    batch << args
    if batch.length >= self.class.get_batch_size
      execute_batch(batch)
      info { "execute batch #{batch.length}, #{cnt} from #{len}" }
      batch = []
    end
    break if stopped
    cnt += 1
  end
  if batch.length > 0
    if stopped
      reschedule_batch(batch)
    else
      execute_batch(batch)
    end
  end
  info { "processes total #{cnt} " }
  self
end