Class: Jets::Processors::MainProcessor
- Inherits:
-
Object
- Object
- Jets::Processors::MainProcessor
- Defined in:
- lib/jets/processors/main_processor.rb
Overview
Node shim calls this class to process both controllers and jobs
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
Instance Method Summary collapse
-
#initialize(event, context, handler) ⇒ MainProcessor
constructor
A new instance of MainProcessor.
- #run ⇒ Object
Constructor Details
#initialize(event, context, handler) ⇒ MainProcessor
Returns a new instance of MainProcessor.
7 8 9 10 11 |
# File 'lib/jets/processors/main_processor.rb', line 7 def initialize(event, context, handler) @event = event @context = context @handler = handler end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'lib/jets/processors/main_processor.rb', line 6 def context @context end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
6 7 8 |
# File 'lib/jets/processors/main_processor.rb', line 6 def event @event end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
6 7 8 |
# File 'lib/jets/processors/main_processor.rb', line 6 def handler @handler end |
Instance Method Details
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jets/processors/main_processor.rb', line 13 def run # Use the handler to deduce app code to run. # Example handlers: handlers/controllers/posts.create, handlers/jobs/sleep.perform # # deducer = Jets::Processors::Deducer.new("handlers/controllers/posts.create") # deducer = Jets::Processors::Deducer.new(handler) begin # Examples: # deducer.code => PostsController.process(event, context, "show") # deducer.path => app/controllers/posts_controller.rb # # deducer.code => HardJob.process(event, context, "dig") # deducer.path => app/jobs/hard_job.rb # # deducer.code => HelloFunction.process(event, context, "world") # deducer.path => app/functions/hello.rb deducer.load_class # result = PostsController.process(event, context, "create") result = instance_eval(deducer.code, deducer.path) result = HashWithIndifferentAccess.new(result) if result.is_a?(Hash) Jets.increase_call_count if result.is_a?(Hash) && result["headers"] # API Gateway is okay with the header values as Integers but # ELBs are more strict about this and require the header values to be Strings result["headers"]["x-jets-call-count"] = Jets.call_count.to_s result["headers"]["x-jets-prewarm-count"] = Jets.prewarm_count.to_s end result # Additional rescue Exception as a paranoid measure. We want to make sure # that we always report the exception. This is the last line of defense. # Note: This only happens when the code is running in Lambda. rescue => exception Jets.report_exception(exception) raise(exception) end end |