Skip to content

Commit

Permalink
Log listener to read IDENTIFIER environment variable if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
t-persson committed Jul 30, 2024
1 parent cc16985 commit 951562e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions projects/log_listener/src/log_listener/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,37 @@
class Listener(threading.Thread):
"""Listen to log messages from ETOS executions."""

__tercc = None
__identifier = None
__stop = False
rabbitmq = None
logger = logging.getLogger(__name__)

def __init__(self, lock: threading.Lock, log_file: pathlib.Path, event_file: pathlib.Path):
"""Initialize ETOS library."""
super().__init__()
self.identifier = self.tercc.meta.event_id
self.lock = lock
self.log_file = log_file
self.event_file = event_file
with self.lock:
with self.event_file.open() as _event_file:
self.id = len(_event_file.readlines()) + 1

@property
def identifier(self) -> str:
"""Get ETOS identifier from environment."""
if self.__identifier is None:
if os.getenv("IDENTIFIER") is not None:
self.__identifier = os.getenv("IDENTIFIER", "Unknown")
else:
self.__identifier = self.tercc.meta.event_id
return self.__identifier

@property
def tercc(self) -> EiffelTestExecutionRecipeCollectionCreatedEvent:
"""Test execution recipe collection created event from environment."""
if self.__tercc is None:
tercc = EiffelTestExecutionRecipeCollectionCreatedEvent()
tercc.rebuild(json.loads(os.getenv("TERCC")))
self.__tercc = tercc
return self.__tercc
tercc = EiffelTestExecutionRecipeCollectionCreatedEvent()
tercc.rebuild(json.loads(os.getenv("TERCC")))
return tercc

def new_event(self, event: dict, _: Optional[str] = None) -> None:
"""Get a new event from the internal RabbitMQ bus and write it to file."""
Expand Down

0 comments on commit 951562e

Please sign in to comment.