Class: Jets::PolyFun::NodeExecutor
- Inherits:
-
BaseExecutor
- Object
- BaseExecutor
- Jets::PolyFun::NodeExecutor
- Defined in:
- lib/jets/poly_fun/node_executor.rb
Instance Method Summary collapse
- #async_code ⇒ Object
- #async_syntax? ⇒ Boolean
- #callback_code ⇒ Object
-
#code ⇒ Object
Code for wrapper script that mimics lambda execution.
Methods inherited from BaseExecutor
#cleanup, #copy_src_to_temp, #create_tmpdir, #handler, #initialize, #lambda_executor_script, #run, #run_lambda_executor, #write
Constructor Details
This class inherits a constructor from Jets::PolyFun::BaseExecutor
Instance Method Details
#async_code ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jets/poly_fun/node_executor.rb', line 26 def async_code "var event = process.argv[2]\nevent = JSON.parse(event)\nvar context = {}\n\nvar app = require(\"./\#{@task.meth}.js\")\napp.\#{handler}(event, context).then(resp => console.log(JSON.stringify(resp)))\n" end |
#async_syntax? ⇒ Boolean
20 21 22 23 24 |
# File 'lib/jets/poly_fun/node_executor.rb', line 20 def async_syntax? app_path = Jets.root + @task.handler_path.sub('handlers/', 'app/') source_code = IO.read(app_path) source_code.match(/=\s*async.*\(/) end |
#callback_code ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jets/poly_fun/node_executor.rb', line 38 def callback_code "function callback(error, response) {\nvar text = JSON.stringify(response)\nconsole.log(text)\n}\n\nvar event = process.argv[2]\nevent = JSON.parse(event)\nvar context = {}\n\nvar app = require(\"./\#{@task.meth}.js\")\nvar resp = app.\#{handler}(event, context, callback)\n" end |
#code ⇒ Object
Code for wrapper script that mimics lambda execution. Wrapper script usage:
node WRAPPER_SCRIPT EVENT
Example:
node /tmp/jets/demo/executor/20180804-12816-imqb9/lambda_executor.js '{}'
11 12 13 14 15 16 17 |
# File 'lib/jets/poly_fun/node_executor.rb', line 11 def code if async_syntax? async_code else callback_code end end |