forked from amundsen-io/amundsendatabuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generic_loader.py
57 lines (43 loc) · 1.28 KB
/
generic_loader.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
# Copyright Contributors to the Amundsen project.
# SPDX-License-Identifier: Apache-2.0
import logging
from pyhocon import ConfigTree # noqa: F401
from typing import Optional, Any # noqa: F401
from databuilder.loader.base_loader import Loader
LOGGER = logging.getLogger(__name__)
CALLBACK_FUNCTION = 'callback_function'
def log_call_back(record):
"""
A Sample callback function. Implement any function follows this function's signature to fit your needs.
:param record:
:return:
"""
LOGGER.info('record: {}'.format(record))
class GenericLoader(Loader):
"""
Loader class to call back a function provided by user
"""
def init(self, conf):
# type: (ConfigTree) -> None
"""
Initialize file handlers from conf
:param conf:
"""
self.conf = conf
self._callback_func = self.conf.get(CALLBACK_FUNCTION, log_call_back)
def load(self, record):
# type: (Optional[Any]) -> None
"""
Write record to function
:param record:
:return:
"""
if not record:
return
self._callback_func(record)
def close(self):
# type: () -> None
pass
def get_scope(self):
# type: () -> str
return "loader.generic"