class MultipleMan::Runner
Constants
- MODES
Attributes
mode[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/multiple_man/runner.rb, line 10 def initialize(options = {}) @mode = options.fetch(:mode, :general) raise ArgumentError, "undefined mode: #{mode}" unless MODES.include?(mode) end
Public Instance Methods
run()
click to toggle source
# File lib/multiple_man/runner.rb, line 16 def run trap_signals! preload_framework! channel.prefetch(prefetch_size) build_listener.listen rescue ShutDown connection.close end
Private Instance Methods
build_listener()
click to toggle source
# File lib/multiple_man/runner.rb, line 53 def build_listener listener_class.new( queue: channel.queue(*queue_params), subscribers: listeners, topic: topic_name ) end
channel()
click to toggle source
# File lib/multiple_man/runner.rb, line 77 def channel @channel ||= connection.create_channel end
config()
click to toggle source
# File lib/multiple_man/runner.rb, line 85 def config MultipleMan.configuration end
connection()
click to toggle source
# File lib/multiple_man/runner.rb, line 81 def connection Connection.connection end
listener_class()
click to toggle source
# File lib/multiple_man/runner.rb, line 61 def listener_class if seeding? Consumers::Seed else Consumers::General end end
preload_framework!()
click to toggle source
# File lib/multiple_man/runner.rb, line 41 def preload_framework! Rails.application.eager_load! if defined?(Rails) if defined?(Hanami) if Hanami::Application.respond_to?(:preload_applications!) Hanami::Application.preload_applications! end if Hanami.respond_to?(:boot) Hanami.boot end end end
queue_params()
click to toggle source
# File lib/multiple_man/runner.rb, line 69 def queue_params if seeding? ["#{queue_name}.seed", durable: false, auto_delete: true] else [queue_name, durable: true, auto_delete: false] end end
seeding?()
click to toggle source
# File lib/multiple_man/runner.rb, line 89 def seeding? mode == :seed end
trap_signals!()
click to toggle source
# File lib/multiple_man/runner.rb, line 31 def trap_signals! handler = proc do |signal| puts "received #{Signal.signame(signal)}" raise ShutDown end %w(INT QUIT TERM).each { |signal| Signal.trap(signal, handler) } end