11'''
2- Copyright 2015-2017 HDE, Inc.
2+ Copyright 2015-2018 HDE, Inc.
33Licensed under MIT.
44'''
55
1515
1616from . import event
1717from . import context
18- from .environment_variables import set_environment_variables
18+ from .environment_variables import set_environment_variables , export_variables
1919from .timeout import time_limit
2020from .timeout import TimeoutException
2121
3131EXITCODE_ERR = 1
3232
3333
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+
3445def run (args ):
3546 # set env vars if path to json file was given
3647 set_environment_variables (args .environment_variables )
@@ -41,16 +52,23 @@ def run(args):
4152 load_lib (args .library )
4253 request_id = uuid .uuid4 ()
4354 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+
4461
62+ def _runner (request_id , event , context , func ):
4563 logger = logging .getLogger ()
4664 result = None
4765
48- logger .info ("Event: {}" .format (e ))
66+ logger .info ("Event: {}" .format (event ))
4967
5068 logger .info ("START RequestId: {}" .format (request_id ))
5169
5270 start_time = timeit .default_timer ()
53- result , err_type = execute (func , e , c )
71+ result , err_type = execute (func , event , context )
5472 end_time = timeit .default_timer ()
5573
5674 logger .info ("END RequestId: {}" .format (request_id ))
@@ -64,8 +82,7 @@ def run(args):
6482 logger .info ("REPORT RequestId: {}\t Duration: {}" .format (
6583 request_id , duration ))
6684
67- if err_type is not None :
68- sys .exit (EXITCODE_ERR )
85+ return (result , err_type )
6986
7087
7188def load_lib (path ):
0 commit comments