Class: Superbolt::App

Inherits:
Object
  • Object
show all
Defined in:
lib/superbolt/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ App

Returns a new instance of App.



6
7
8
9
10
11
12
13
# File 'lib/superbolt/app.rb', line 6

def initialize(name, options={})
  @name                = name
  @env                 = options[:env] || Superbolt.env
  @logger              = options[:logger] || Logger.new($stdout)
  @config              = options[:config] || Superbolt.config
  @runner_type         = options[:runner] || config.runner || :default
  @error_notifier_type = options[:error_notifier] || Superbolt.error_notifier
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/superbolt/app.rb', line 3

def config
  @config
end

#envObject (readonly)

Returns the value of attribute env.



3
4
5
# File 'lib/superbolt/app.rb', line 3

def env
  @env
end

#error_notifier_typeObject (readonly)

Returns the value of attribute error_notifier_type.



3
4
5
# File 'lib/superbolt/app.rb', line 3

def error_notifier_type
  @error_notifier_type
end

#loggerObject

Returns the value of attribute logger.



4
5
6
# File 'lib/superbolt/app.rb', line 4

def logger
  @logger
end

#runner_typeObject (readonly)

Returns the value of attribute runner_type.



3
4
5
# File 'lib/superbolt/app.rb', line 3

def runner_type
  @runner_type
end

Instance Method Details

#connectionObject



19
20
21
# File 'lib/superbolt/app.rb', line 19

def connection
  @connection ||= Connection::Queue.new(name, config)
end

#default_error_notifierObject



68
69
70
# File 'lib/superbolt/app.rb', line 68

def default_error_notifier
  error_notifier_map[:none]
end

#default_runnerObject



49
50
51
# File 'lib/superbolt/app.rb', line 49

def default_runner
  runner_map[:ack_one]
end

#error_notifierObject



53
54
55
# File 'lib/superbolt/app.rb', line 53

def error_notifier
  @error_notifier ||= error_notifier_class.new(logger)
end

#error_notifier_classObject



57
58
59
# File 'lib/superbolt/app.rb', line 57

def error_notifier_class
  error_notifier_map[error_notifier_type] || default_error_notifier
end

#error_notifier_mapObject



61
62
63
64
65
66
# File 'lib/superbolt/app.rb', line 61

def error_notifier_map
  {
    airbrake: ErrorNotifier::Airbrake,
    none:     ErrorNotifier::None
  }
end

#nameObject



15
16
17
# File 'lib/superbolt/app.rb', line 15

def name
  env ? "#{@name}_#{env}" : @name
end

#queueObject



27
28
29
# File 'lib/superbolt/app.rb', line 27

def queue
  connection.q
end

#quit(message = 'no message given') ⇒ Object



72
73
74
75
76
# 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) ⇒ Object



31
32
33
# File 'lib/superbolt/app.rb', line 31

def run(&block)
  runner_class.new(queue, error_notifier, logger, block).run
end

#runner_classObject



35
36
37
# File 'lib/superbolt/app.rb', line 35

def runner_class
  runner_map[runner_type] || default_runner
end

#runner_mapObject



39
40
41
42
43
44
45
46
47
# 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