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