diff --git a/dbt_common/events/event_manager.py b/dbt_common/events/event_manager.py index 96e61f6b..507588f3 100644 --- a/dbt_common/events/event_manager.py +++ b/dbt_common/events/event_manager.py @@ -1,15 +1,15 @@ import os import traceback -from typing import Callable, List, Optional, Protocol, Tuple +from typing import List, Optional, Protocol, Tuple -from dbt_common.events.base_types import BaseEvent, EventLevel, msg_from_base_event, EventMsg +from dbt_common.events.base_types import BaseEvent, EventLevel, msg_from_base_event, TCallback from dbt_common.events.logger import LoggerConfig, _Logger, _TextLogger, _JsonLogger, LineFormat class EventManager: def __init__(self) -> None: self.loggers: List[_Logger] = [] - self.callbacks: List[Callable[[EventMsg], None]] = [] + self.callbacks: List[TCallback] = [] def fire_event(self, e: BaseEvent, level: Optional[EventLevel] = None) -> None: msg = msg_from_base_event(e, level=level) @@ -37,13 +37,16 @@ def add_logger(self, config: LoggerConfig) -> None: ) self.loggers.append(logger) + def add_callback(self, callback: TCallback) -> None: + self.callbacks.append(callback) + def flush(self) -> None: for logger in self.loggers: logger.flush() class IEventManager(Protocol): - callbacks: List[Callable[[EventMsg], None]] + callbacks: List[TCallback] loggers: List[_Logger] def fire_event(self, e: BaseEvent, level: Optional[EventLevel] = None) -> None: @@ -52,6 +55,9 @@ def fire_event(self, e: BaseEvent, level: Optional[EventLevel] = None) -> None: def add_logger(self, config: LoggerConfig) -> None: ... + def add_callback(self, callback: TCallback) -> None: + ... + class TestEventManager(IEventManager): __test__ = False