15
15
16
16
from . import event
17
17
from . import context
18
- from .environment_variables import set_environment_variables
18
+ from .environment_variables import set_environment_variables , export_variables
19
19
from .timeout import time_limit
20
20
from .timeout import TimeoutException
21
21
31
31
EXITCODE_ERR = 1
32
32
33
33
34
+ def call (func , event , timeout , environment_variables = {}, arn_string = "" , version_name = "" , library = None ):
35
+ export_variables (environment_variables )
36
+ e = json .loads (event )
37
+ c = context .Context (timeout , arn_string , version_name )
38
+ if library is not None :
39
+ load_lib (library )
40
+ request_id = uuid .uuid4 ()
41
+
42
+ return _runner (request_id , e , c , func )
43
+
44
+
34
45
def run (args ):
35
46
# set env vars if path to json file was given
36
47
set_environment_variables (args .environment_variables )
@@ -41,16 +52,23 @@ def run(args):
41
52
load_lib (args .library )
42
53
request_id = uuid .uuid4 ()
43
54
func = load (request_id , args .file , args .function )
55
+
56
+ (result , err_type ) = _runner (request_id , e , c , func )
57
+
58
+ if err_type is not None :
59
+ sys .exit (EXITCODE_ERR )
60
+
44
61
62
+ def _runner (request_id , event , context , func ):
45
63
logger = logging .getLogger ()
46
64
result = None
47
65
48
- logger .info ("Event: {}" .format (e ))
66
+ logger .info ("Event: {}" .format (event ))
49
67
50
68
logger .info ("START RequestId: {}" .format (request_id ))
51
69
52
70
start_time = timeit .default_timer ()
53
- result , err_type = execute (func , e , c )
71
+ result , err_type = execute (func , event , context )
54
72
end_time = timeit .default_timer ()
55
73
56
74
logger .info ("END RequestId: {}" .format (request_id ))
@@ -64,8 +82,7 @@ def run(args):
64
82
logger .info ("REPORT RequestId: {}\t Duration: {}" .format (
65
83
request_id , duration ))
66
84
67
- if err_type is not None :
68
- sys .exit (EXITCODE_ERR )
85
+ return (result , err_type )
69
86
70
87
71
88
def load_lib (path ):
0 commit comments