Skip to content

Commit

Permalink
Add a disable flag
Browse files Browse the repository at this point in the history
  • Loading branch information
t-persson committed Aug 30, 2024
1 parent ebbc357 commit a151509
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/etos_test_runner/lib/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@
# limitations under the License.
# -*- coding: utf-8 -*-
"""ETOS internal message bus module."""
import os
from etos_lib import ETOS
from etos_lib.logging.log_publisher import RabbitMQLogPublisher


class EventPublisher:
"""EventPublisher helps in sending events to the internal ETOS message bus."""

disabled = False

def __init__(self, etos: ETOS):
"""Set up, but do not start, the RabbitMQ publisher."""
if os.getenv("DISABLE_EVENT_PUBLISHING", "false").lower() == "true":
self.disabled = True
publisher = etos.config.get("event_publisher")
if publisher is None:
if self.disabled is False and publisher is None:
config = etos.config.etos_rabbitmq_publisher_data()
# This password should already be decrypted when setting up the logging.
config["password"] = etos.config.get("etos_rabbitmq_password")
Expand All @@ -40,13 +45,17 @@ def __del__(self):

def close(self):
"""Close the RabbitMQ publisher if it is started."""
if self.publisher.is_alive():
if self.publisher is not None and self.publisher.is_alive():
self.publisher.wait_for_unpublished_events()
self.publisher.close()
self.publisher.wait_close()

def publish(self, event: dict):
"""Publish an event to the ETOS internal message bus."""
if self.disabled:
return
if self.publisher is None:
return
if not self.publisher.started:
self.publisher.start()
routing_key = f"{self.identifier}.event.{event.get('event')}"
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ setenv = TEST_ARTIFACT_PATH={toxworkdir}/artifact
TEST_LOCAL_PATH={toxworkdir}/local
GLOBAL_ARTIFACT_PATH={toxworkdir}/global
ETOS_ENABLE_SENDING_LOGS=false
DISABLE_EVENT_PUBLISHING=true
commands =
pytest -s --log-cli-level="DEBUG" --log-format="%(levelname)s: %(message)s" {posargs}

Expand Down

0 comments on commit a151509

Please sign in to comment.