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.
14
15
16
17
|
# File 'lib/jets/poly_fun.rb', line 14
def initialize(app_class, app_meth)
@app_class = app_class @app_meth = app_meth.to_sym
end
|
Instance Method Details
#check_private_method! ⇒ Object
75
76
77
78
79
80
|
# File 'lib/jets/poly_fun.rb', line 75
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/jets/poly_fun.rb', line 43
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.classify}Error".constantize
raise error_class.new(resp["errorMessage"], backtrace)
end
|
#run(event, context = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/jets/poly_fun.rb', line 19
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
36
37
38
39
40
41
|
# File 'lib/jets/poly_fun.rb', line 36
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
65
66
67
68
69
70
71
72
|
# File 'lib/jets/poly_fun.rb', line 65
def task
task = @app_class.all_public_tasks[@app_meth]
unless task
raise "Unable to find #{@app_class}##{@app_meth}"
end
task
end
|