Class: Jets::PolyFun
- Inherits:
-
Object
show all
- Extended by:
- Memoist
- Defined in:
- lib/jets/poly_fun.rb,
lib/jets/poly_fun/node_error.rb,
lib/jets/poly_fun/python_error.rb,
lib/jets/poly_fun/base_executor.rb,
lib/jets/poly_fun/node_executor.rb,
lib/jets/poly_fun/lambda_executor.rb,
lib/jets/poly_fun/python_executor.rb
Defined Under Namespace
Classes: BaseExecutor, LambdaExecutor, NodeError, NodeExecutor, PythonError, PythonExecutor
Instance Method Summary
collapse
Constructor Details
#initialize(app_class, app_meth) ⇒ PolyFun
Returns a new instance of PolyFun.
5
6
7
8
|
# File 'lib/jets/poly_fun.rb', line 5
def initialize(app_class, app_meth)
@app_class = app_class @app_meth = app_meth.to_sym
end
|
Instance Method Details
#check_private_method! ⇒ Object
66
67
68
69
70
71
|
# File 'lib/jets/poly_fun.rb', line 66
def check_private_method!
private_detected = @app_class.all_private_tasks.keys.include?(@app_meth)
return unless private_detected
raise "The #{@app_class}##{@app_meth} is a private method. Unable to call it unless it is public"
end
|
#raise_error(resp) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/jets/poly_fun.rb', line 34
def raise_error(resp)
backtrace = resp["stackTrace"] + caller
backtrace = backtrace.map { |l| l.sub(/^\s+/,'') }
backtrace = backtrace.map do |l|
if l.include?(Jets.build_root) && !l.include?("lambda_executor.")
l.sub(/\/tmp\/jets.*executor\/\d{8}-+.*?\//, '')
else
l
end
end
error_class = "Jets::PolyFun::#{task.lang.to_s.camelize}Error".constantize
raise error_class.new(resp["errorMessage"], backtrace)
end
|
#run(event, context = {}) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/jets/poly_fun.rb', line 10
def run(event, context={})
check_private_method!
if task.lang == :ruby
run_ruby_code(event, context)
else
executor = LambdaExecutor.new(task)
resp = executor.run(event, context)
if resp["errorMessage"]
raise_error(resp)
end
resp
end
end
|
#run_ruby_code(event, context) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/jets/poly_fun.rb', line 27
def run_ruby_code(event, context)
@app_class.process(event, context, @app_meth)
rescue Exception => e
Jets.on_exception(e)
raise(e)
end
|
#task ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'lib/jets/poly_fun.rb', line 56
def task
task = @app_class.all_public_tasks[@app_meth]
unless task
raise "Unable to find #{@app_class}##{@app_meth}"
end
task
end
|