Sha256: 937ab5e9be512b990fcb588db876a67c865468a4dfe182466d5751c4c37c0a39

Contents?: true

Size: 722 Bytes

Versions: 10

Compression:

Stored size: 722 Bytes

Contents

# frozen_string_literal: true

module Boppers
  class Runner
    def boppers
      Boppers.configuration.boppers
    end

    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

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

      threads.each(&:join)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
boppers-0.0.10 lib/boppers/runner.rb
boppers-0.0.9 lib/boppers/runner.rb
boppers-0.0.8 lib/boppers/runner.rb
boppers-0.0.7 lib/boppers/runner.rb
boppers-0.0.6 lib/boppers/runner.rb
boppers-0.0.5 lib/boppers/runner.rb
boppers-0.0.4 lib/boppers/runner.rb
boppers-0.0.3 lib/boppers/runner.rb
boppers-0.0.2 lib/boppers/runner.rb
boppers-0.0.1 lib/boppers/runner.rb