Class: CottonTail::App
- Inherits:
-
Object
- Object
- CottonTail::App
- Defined in:
- lib/cotton_tail/app.rb
Overview
App is the main class for a CottonTail server
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(queue_strategy: Queue::Bunny, env: {}, connection: Bunny.new) ⇒ App
constructor
A new instance of App.
-
#queue(name) ⇒ Object
Get a single message queue.
- #queues ⇒ Object
- #routes ⇒ Object
-
#run ⇒ Object
Start the app, process all pending messages, and then shutdown.
- #start ⇒ Object
Constructor Details
#initialize(queue_strategy: Queue::Bunny, env: {}, connection: Bunny.new) ⇒ App
Returns a new instance of App.
8 9 10 11 12 |
# File 'lib/cotton_tail/app.rb', line 8 def initialize(queue_strategy: Queue::Bunny, env: {}, connection: Bunny.new) @dependencies = { queue_strategy: queue_strategy, connection: connection } @env = env @connection = connection.start end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/cotton_tail/app.rb', line 6 def env @env end |
Instance Method Details
#config ⇒ Object
14 15 16 |
# File 'lib/cotton_tail/app.rb', line 14 def config @config ||= Configuration.new(middleware: Middleware.default_stack(self)) end |
#queue(name) ⇒ Object
Get a single message queue
23 24 25 |
# File 'lib/cotton_tail/app.rb', line 23 def queue(name) queues[name] end |
#queues ⇒ Object
18 19 20 |
# File 'lib/cotton_tail/app.rb', line 18 def queues routes.queues end |
#routes ⇒ Object
39 40 41 |
# File 'lib/cotton_tail/app.rb', line 39 def routes @routes ||= DSL::Routes.new(**@dependencies) end |
#run ⇒ Object
Start the app, process all pending messages, and then shutdown
28 29 30 |
# File 'lib/cotton_tail/app.rb', line 28 def run supervisors.map(&:run).each(&:join) end |
#start ⇒ Object
32 33 34 35 36 37 |
# File 'lib/cotton_tail/app.rb', line 32 def start supervisors.map(&:start) puts 'Waiting for messages ...' sleep 0.01 while running? end |