Class: Superbolt::App
- Inherits:
-
Object
- Object
- Superbolt::App
- Defined in:
- lib/superbolt/app.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#error_notifier_type ⇒ Object
readonly
Returns the value of attribute error_notifier_type.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#runner_type ⇒ Object
readonly
Returns the value of attribute runner_type.
Instance Method Summary collapse
- #connection ⇒ Object
- #default_error_notifier ⇒ Object
- #default_runner ⇒ Object
- #error_notifier ⇒ Object
- #error_notifier_class ⇒ Object
- #error_notifier_map ⇒ Object
-
#initialize(name, options = {}) ⇒ App
constructor
A new instance of App.
- #name ⇒ Object
- #queue ⇒ Object
- #quit(message = 'no message given') ⇒ Object
- #run(&block) ⇒ Object
- #runner_class ⇒ Object
- #runner_map ⇒ Object
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, ={}) @name = name @env = [:env] || Superbolt.env @logger = [:logger] || Logger.new($stdout) @config = [:config] || Superbolt.config @runner_type = [:runner] || config.runner || :default @error_notifier_type = [:error_notifier] || Superbolt.error_notifier end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/superbolt/app.rb', line 3 def config @config end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
3 4 5 |
# File 'lib/superbolt/app.rb', line 3 def env @env end |
#error_notifier_type ⇒ Object (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 |
#logger ⇒ Object
Returns the value of attribute logger.
4 5 6 |
# File 'lib/superbolt/app.rb', line 4 def logger @logger end |
#runner_type ⇒ Object (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
#connection ⇒ Object
19 20 21 |
# File 'lib/superbolt/app.rb', line 19 def connection @connection ||= Connection::Queue.new(name, config) end |
#default_error_notifier ⇒ Object
68 69 70 |
# File 'lib/superbolt/app.rb', line 68 def default_error_notifier error_notifier_map[:none] end |
#default_runner ⇒ Object
49 50 51 |
# File 'lib/superbolt/app.rb', line 49 def default_runner runner_map[:ack_one] end |
#error_notifier ⇒ Object
53 54 55 |
# File 'lib/superbolt/app.rb', line 53 def error_notifier @error_notifier ||= error_notifier_class.new(logger) end |
#error_notifier_class ⇒ Object
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_map ⇒ Object
61 62 63 64 65 66 |
# File 'lib/superbolt/app.rb', line 61 def error_notifier_map { airbrake: ErrorNotifier::Airbrake, none: ErrorNotifier::None } end |
#name ⇒ Object
15 16 17 |
# File 'lib/superbolt/app.rb', line 15 def name env ? "#{@name}_#{env}" : @name end |
#queue ⇒ Object
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(='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_class ⇒ Object
35 36 37 |
# File 'lib/superbolt/app.rb', line 35 def runner_class runner_map[runner_type] || default_runner end |
#runner_map ⇒ Object
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 |