Added trigger level
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Pünkösd Marcell 2021-07-28 13:35:40 +02:00
parent 5d83767d83
commit fbfb379e86
2 changed files with 11 additions and 8 deletions

View File

@ -38,20 +38,19 @@ if config.SENTRY_DSN:
def setup_rabbit(mqtt_: MQTT) -> None:
logging.info("Connecting to RabbitMQ")
logging.info("Connecting to RabbitMQ...")
credentials = pika.PlainCredentials(config.RABBIT_USERNAME, config.RABBIT_PASSWORD)
connection = pika.BlockingConnection(pika.ConnectionParameters(host=config.RABBIT_HOSTNAME,
credentials=credentials,
heartbeat=30,
socket_timeout=45))
channel = connection.channel()
channel.exchange_declare(exchange=config.RABBIT_EXCHANGE,
exchange_type='fanout')
channel.exchange_declare(exchange=config.RABBIT_EXCHANGE, exchange_type='fanout')
queue = channel.queue_declare(durable=True, auto_delete=True, queue=uuid.uuid4().urn.split(':')[2],
exclusive=True).method.queue
channel.queue_bind(exchange=config.RABBIT_EXCHANGE, queue=queue)
channel.basic_consume(queue=queue, on_message_callback=on_message_creator(mqtt_), auto_ack=True)
logging.debug("Starting consumption")
logging.debug("Starting consumption...")
channel.start_consuming()
@ -71,7 +70,7 @@ def on_message_creator(mqtt_: MQTT):
return
# TODO: strurnus should not be hardcoded here
if (msg_json['class'] == 'sturnus') and (msg_json['probability'] > 0.51):
if (msg_json['class'] == 'sturnus') and (msg_json['probability'] > config.TRIGGER_LEVEL):
r = requests.get(f"http://{config.INPUT_HOSTNAME}/sample/{msg_json['tag']}")
r.raise_for_status()
if 'device_id' not in r.json():
@ -86,9 +85,12 @@ def on_message_creator(mqtt_: MQTT):
if __name__ == "__main__":
logging.basicConfig(stream=sys.stdout, format="%(asctime)s - %(name)s [%(levelname)s]: %(message)s",
level=logging.DEBUG if '--debug' in sys.argv else logging.INFO)
logging.info("Guard service starting")
logging.basicConfig(
stream=sys.stdout,
format="%(asctime)s - %(name)s [%(levelname)s]: %(message)s",
level=logging.DEBUG if '--debug' in sys.argv else logging.INFO
)
logging.info("Guard service starting...")
mqtt = MQTT()
mqtt.topic = config.MQTT_TOPIC
mqtt.connect()

View File

@ -30,3 +30,4 @@ MQTT_PASSWORD = os.getenv("GUARD_MQTT_PASSWORD", "guard-service")
MQTT_TOPIC = os.getenv("GUARD_MQTT_TOPIC", "guard-service")
INPUT_HOSTNAME = os.getenv("INPUT_SVC_HOSTNAME", "input-service")
TRIGGER_LEVEL = float(os.environ.get("TRIGGER_LEVEL", 0.51))