-
Notifications
You must be signed in to change notification settings - Fork 5
/
jean.py
63 lines (48 loc) · 1.46 KB
/
jean.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import logging
import traceback
from typing import Dict
try:
import unzip_requirements # NOQA
except ImportError:
pass
from xlibs import exc, response
from xlibs.jean import constants, utils
logger = logging.getLogger()
logger.setLevel(logging.WARNING)
def handler(event: Dict, context: Dict) -> Dict:
'''Jean Lambda entry point handler
:arg event: (dict) event input received from the invoker/trigger
:arg context: (dict) contextual data provided by the Lambda platform
'''
try:
result = execute(
options=event,
)
return response.build(
status=200,
data=result,
)
except Exception as error:
logger.exception(error)
return response.build(
status=500,
error={
'type': type(error).__name__,
'description': str(error),
'trace': traceback.format_exc(),
},
original_request=event,
)
def execute(*, options: Dict) -> Dict:
'''Execute a request received by the Jean Lambda'''
is_request_valid, validation_msg = utils.validate_request(
options=options,
required_args=constants.REQUIRED_ARGS,
)
if not is_request_valid:
raise exc.XLambdaExceptionInvalidRequest(validation_msg)
options['forecast'] = utils.forecasting(
metrics=options['metrics'],
timeframe=options['timeframe'],
)
return options