call

in core/ruby2.5Action/rackapp/run.rb [24:59]


  def call(env)
    if !File.exist? ENTRYPOINT then
      return ErrorResponse.new 'Invalid Action: no action file found', 500
    end

    
    body = Rack::Request.new(env).body.read
    data = JSON.parse(body) || {}
    env = {'BUNDLE_GEMFILE' => PROGRAM_DIR + 'Gemfile'}
    data.each do |key, value|
      if key != 'value'
        env["__OW_#{key.upcase}"] = value if value && value.is_a?(String)
      end
    end

    
    File.write PARAM, data['value'].to_json

    
    if system(env, "bundle exec ruby -r #{ENTRYPOINT} #{RACKAPP_DIR}runner.rb | tee #{OUT}") then
      if File.exist? RESULT then
        result = File.read(RESULT)
        if valid_json_or_array(result) then
          SuccessResponse.new(JSON.parse(result))
        else
          warn "Result must be an array but has type '#{result.class.to_s}': #{result}"
          ErrorResponse.new 'The action did not return a dictionary or array.', 502
        end
      else
        ErrorResponse.new 'Invalid Action: An error occurred running the action', 502
      end
    else
      ErrorResponse.new "Invalid Action: the execution was not successful. / #{File.read(OUT)}}", 502
    end
  end