Skip to content

Commit

Permalink
Add env variable to configure ingest topic prepend string
Browse files Browse the repository at this point in the history
  • Loading branch information
Teddy-1000 committed Dec 9, 2024
1 parent a32542d commit 1c44ac4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ingest/api/send_mqtt.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import os
import logging
import json
from paho.mqtt import client as mqtt_client
from fastapi import HTTPException

logger = logging.getLogger(__name__)

if "MQTT_TOPIC_PREPEND" in os.environ:
mqtt_topic_prepend = os.getenv("MQTT_TOPIC_PREPEND", "")
mqtt_topic_prepend = mqtt_topic_prepend if not mqtt_topic_prepend.endswith("/") else mqtt_topic_prepend + "/"

def connect_mqtt(mqtt_conf: dict):

def connect_mqtt(mqtt_conf: dict):
def on_connect(client, userdata, flags, rc, properties=None):
if rc == 0:
logger.info("Connected to MQTT Broker!")
Expand All @@ -34,7 +38,7 @@ def on_disconnect(client, userdata, flags, rc, properties):

def send_message(topic: str, message: str, client: object):
if len(topic) != 0:
mqtt_topic = topic
mqtt_topic = mqtt_topic_prepend + topic
try:
if isinstance(message, dict):
client.publish(mqtt_topic, json.dumps(message))
Expand Down

1 comment on commit 1c44ac4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Unit Test Coverage Report
FileStmtsMissCoverMissing
__init__.py00100% 
datastore_pb2.py614821%34–81
datastore_pb2_grpc.py542750%15–16, 19, 65–80, 121–123, 128–130, 135–137, 142–144, 148–173, 219, 246, 273, 300
export_metrics.py100100% 
grpc_getter.py201145%15–19, 23–26, 30–32, 36–38
locustfile.py15150%1–31
main.py44784%49, 54, 64, 74–75, 85–86
metadata_endpoints.py663252%45–54, 58, 85, 100–220, 224
response_classes.py50100% 
utilities.py1803978%21, 39, 46, 68–71, 79–90, 95–102, 122, 126, 128, 156, 162, 180, 238–244, 248–250, 280, 284, 306, 311
custom_geo_json
   edr_feature_collection.py60100% 
formatters
   __init__.py110100% 
   covjson.py60198%91
   geojson.py21290%27, 52
openapi
   custom_dimension_examples.py40100% 
   edr_query_parameter_descriptions.py110100% 
   openapi_examples.py130100% 
routers
   __init__.py00100% 
   edr.py101496%348–349, 438–439
   feature.py471960%99–132, 148–153, 159–181
TOTAL72920572% 

Title Coverage Tests Skipped Failures Errors Time
API Unit Tests Coverage 40 0 💤 0 ❌ 0 🔥 1.909s ⏱️
Ingest Unit Tests Coverage 16 0 💤 0 ❌ 0 🔥 11.524s ⏱️

Please sign in to comment.