Sha256: 5543228a2f39d3645348b34f64f4d222dfc2e25fb78b8e4ef1f06435fbda5952

Contents?: true

Size: 1.2 KB

Versions: 148

Compression:

Stored size: 1.2 KB

Contents

class Jets::PolyFun
  class NodeExecutor < BaseExecutor
    # 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 '{}'
    #
    def code
      if async_syntax?
        async_code
      else
        callback_code
      end
    end

    # https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html
    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

    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


    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
  end
end

Version data entries

148 entries across 148 versions & 4 rubygems

Version Path
jets-4.0.12 lib/jets/poly_fun/node_executor.rb
jets-4.0.11 lib/jets/poly_fun/node_executor.rb
jets-4.0.10 lib/jets/poly_fun/node_executor.rb
jets-4.0.9 lib/jets/poly_fun/node_executor.rb
jets-4.0.8 lib/jets/poly_fun/node_executor.rb
jets-4.0.7 lib/jets/poly_fun/node_executor.rb
jets-4.0.6 lib/jets/poly_fun/node_executor.rb
jets-4.0.5 lib/jets/poly_fun/node_executor.rb
jets-4.0.4 lib/jets/poly_fun/node_executor.rb
jets-4.0.3 lib/jets/poly_fun/node_executor.rb
jets-4.0.2 lib/jets/poly_fun/node_executor.rb
jets-4.0.1 lib/jets/poly_fun/node_executor.rb
jets-4.0.0 lib/jets/poly_fun/node_executor.rb
jets-3.2.2 lib/jets/poly_fun/node_executor.rb
jets-3.2.1 lib/jets/poly_fun/node_executor.rb
jets.benforeva-3.0.17.pre.mount.pre.fix lib/jets/poly_fun/node_executor.rb
jets-3.2.0 lib/jets/poly_fun/node_executor.rb
jets-3.1.5 lib/jets/poly_fun/node_executor.rb
jets-3.1.4 lib/jets/poly_fun/node_executor.rb
jets-3.1.3 lib/jets/poly_fun/node_executor.rb