-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy patherror_callbacks.py
52 lines (44 loc) · 1.53 KB
/
error_callbacks.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
import logging
from typing import Callable, Optional
from .models import RawConfluentKafkaMessageProto, Row
ProcessingErrorCallback = Callable[[Exception, Optional[Row], logging.Logger], bool]
ConsumerErrorCallback = Callable[
[Exception, Optional[RawConfluentKafkaMessageProto], logging.Logger], bool
]
ProducerErrorCallback = Callable[[Exception, Optional[Row], logging.Logger], bool]
def default_on_consumer_error(
exc: Exception,
message: Optional[RawConfluentKafkaMessageProto],
logger: logging.Logger,
):
topic, partition, offset = None, None, None
if message is not None:
topic, partition, offset = (
message.topic(),
message.partition(),
message.offset(),
)
logger.exception(
f"Failed to consume a message from Kafka: "
f'partition="{topic}[{partition}]" offset="{offset}"',
)
return False
def default_on_processing_error(
exc: Exception, row: Row, logger: logging.Logger
) -> bool:
logger.exception(
f"Failed to process a Row: "
f'partition="{row.topic}[{row.partition}]" offset="{row.offset}"',
)
return False
def default_on_producer_error(
exc: Exception, row: Optional[Row], logger: logging.Logger
) -> bool:
topic, partition, offset = None, None, None
if row is not None:
topic, partition, offset = row.topic, row.partition, row.offset
logger.exception(
f"Failed to produce a message to Kafka: "
f'partition="{topic}[{partition}]" offset="{offset}"',
)
return False