Class: Boppers::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/boppers/runner.rb

Instance Method Summary collapse

Instance Method Details

#boppersObject



5
6
7
# File 'lib/boppers/runner.rb', line 5

def boppers
  Boppers.configuration.boppers
end

#callObject



29
30
31
32
33
34
35
# File 'lib/boppers/runner.rb', line 29

def call
  threads = boppers.each_with_object([]) do |bopper, buffer|
    buffer << run_bopper(bopper)
  end

  threads.each(&:join)
end

#run_bopper(bopper) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/boppers/runner.rb', line 9

def run_bopper(bopper)
  interval = if bopper.respond_to?(:interval)
               bopper.interval
             else
               60
             end

  Thread.new do
    loop do
      begin
        bopper.call
      rescue StandardError => error
        Boppers.configuration.handle_exception&.call(error)
      end

      sleep interval
    end
  end
end