Class: Amazon::Coral::Orchestrator
- Defined in:
- lib/amazon/coral/orchestrator.rb
Overview
Directs a Job through a Handler chain for processing.
Instance Method Summary collapse
-
#initialize(handlers) ⇒ Orchestrator
constructor
Instantiate an orchestrator with the given list of Handlers.
-
#orchestrate(request) ⇒ Object
Direct the specified request down the Handler chain, invoking first each before method, then in reverse order each after method.
Constructor Details
#initialize(handlers) ⇒ Orchestrator
Instantiate an orchestrator with the given list of Handlers.
14 15 16 17 18 19 |
# File 'lib/amazon/coral/orchestrator.rb', line 14 def initialize(handlers) @log = LogFactory.getLog('Amazon::Coral::Orchestrator') @handlers = handlers @log.info "Initialized with handlers: #{handlers}" end |
Instance Method Details
#orchestrate(request) ⇒ Object
Direct the specified request down the Handler chain, invoking first each before method, then in reverse order each after method. If any exceptions are thrown along the way, orchestration will stop immediately.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/amazon/coral/orchestrator.rb', line 24 def orchestrate(request) @log.debug "Processing request #{request}" job = Job.new(request) stack = [] @handlers.each { |handler| stack << handler @log.debug "Invoking #{handler}.before()" handler.before(job) } stack.reverse.each { |handler| @log.debug "Invoking #{handler}.after()" handler.after(job) } return job.reply end |