Class: Jets::PolyFun::NodeExecutor

Inherits:
BaseExecutor show all
Defined in:
lib/jets/poly_fun/node_executor.rb

Instance Method Summary collapse

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_codeObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/jets/poly_fun/node_executor.rb', line 26

def async_code
  <<-EOL
var event = process.argv[2]
event = JSON.parse(event)
var context = {}

var app = require("./#{@task.meth}.js")
app.#{handler}(event, context).then(resp => console.log(JSON.stringify(resp)))
EOL
end

#async_syntax?Boolean

Returns:

  • (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_codeObject



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
  <<-EOL
function callback(error, response) {
  var text = JSON.stringify(response)
  console.log(text)
}

var event = process.argv[2]
event = JSON.parse(event)
var context = {}

var app = require("./#{@task.meth}.js")
var resp = app.#{handler}(event, context, callback)
EOL
end

#codeObject

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