class Superbolt::App

Attributes

config[R]
env[R]
error_notifier_type[R]
logger[RW]
runner_type[R]

Public Class Methods

new(name, options={}) click to toggle source
# File lib/superbolt/app.rb, line 6
def initialize(name, options={})
  @name                = name
  @env                 = options[:env] || Superbolt.env
  @logger              = options[:logger] || LogStashLogger.new(type: :stdout)
  @config              = options[:config] || Superbolt.config
  @runner_type         = options[:runner] || config.runner || :default
  @error_notifier_type = options[:error_notifier] || Superbolt.error_notifier
end

Public Instance Methods

connection() click to toggle source
# File lib/superbolt/app.rb, line 19
def connection
  @connection ||= Connection::Queue.new(name, config)
end
default_error_notifier() click to toggle source
# File lib/superbolt/app.rb, line 68
def default_error_notifier
  error_notifier_map[:none]
end
default_runner() click to toggle source
# File lib/superbolt/app.rb, line 49
def default_runner
  runner_map[:ack_one]
end
error_notifier() click to toggle source
# File lib/superbolt/app.rb, line 53
def error_notifier
  @error_notifier ||= error_notifier_class.new(logger)
end
error_notifier_class() click to toggle source
# File lib/superbolt/app.rb, line 57
def error_notifier_class
  error_notifier_map[error_notifier_type] || default_error_notifier
end
error_notifier_map() click to toggle source
# File lib/superbolt/app.rb, line 61
def error_notifier_map
  {
    airbrake: ErrorNotifier::Airbrake,
    none:     ErrorNotifier::None
  }
end
name() click to toggle source
# File lib/superbolt/app.rb, line 15
def name
  env ? "#{@name}_#{env}" : @name
end
queue() click to toggle source
# File lib/superbolt/app.rb, line 27
def queue
  connection.q
end
quit(message='no message given') click to toggle source
# File lib/superbolt/app.rb, line 72
def quit(message='no message given')
  logger.info "EXITING Superbolt App listening on queue #{name}: #{message}"
  q.channel.basic_cancel q.channel.consumers.first[0]
  close
end
run(&block) click to toggle source
# File lib/superbolt/app.rb, line 31
def run(&block)
  runner_class.new(queue, error_notifier, logger, block).run
end
runner_class() click to toggle source
# File lib/superbolt/app.rb, line 35
def runner_class
  runner_map[runner_type] || default_runner
end
runner_map() click to toggle source
# File lib/superbolt/app.rb, line 39
def runner_map
  {
    pop:      Runner::Pop,
    ack_one:  Runner::AckOne,
    ack:      Runner::Ack,
    greedy:   Runner::Greedy,
    pg:       Runner::Pg
  }
end