fix rabbit api and add better sentry intergation
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c8c96f3007
commit
46169a54bd
25
src/app.py
25
src/app.py
@ -1,9 +1,14 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
import pika
|
import pika
|
||||||
import requests
|
import requests
|
||||||
|
from sentry_sdk.integrations.logging import LoggingIntegration
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
import uuid
|
||||||
from mqtt_helper import MQTT
|
from mqtt_helper import MQTT
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -16,9 +21,14 @@ __module_name__ = "app"
|
|||||||
__version__text__ = "1"
|
__version__text__ = "1"
|
||||||
|
|
||||||
if config.SENTRY_DSN:
|
if config.SENTRY_DSN:
|
||||||
|
sentry_logging = LoggingIntegration(
|
||||||
|
level=logging.DEBUG, # Capture info and above as breadcrumbs
|
||||||
|
event_level=logging.ERROR # Send errors as events
|
||||||
|
)
|
||||||
sentry_sdk.init(
|
sentry_sdk.init(
|
||||||
dsn=config.SENTRY_DSN,
|
dsn=config.SENTRY_DSN,
|
||||||
send_default_pii=True,
|
send_default_pii=True,
|
||||||
|
integrations=[sentry_logging],
|
||||||
release=config.RELEASE_ID,
|
release=config.RELEASE_ID,
|
||||||
environment=config.RELEASEMODE
|
environment=config.RELEASEMODE
|
||||||
)
|
)
|
||||||
@ -31,13 +41,14 @@ def setup_rabbit() -> None:
|
|||||||
heartbeat=0,
|
heartbeat=0,
|
||||||
socket_timeout=5))
|
socket_timeout=5))
|
||||||
channel = connection.channel()
|
channel = connection.channel()
|
||||||
exchange = channel.exchange_declare(exchange=config.RABBIT_EXCHANGE,
|
channel.exchange_declare(exchange=config.RABBIT_EXCHANGE,
|
||||||
exchange_type='fanout',
|
exchange_type='fanout',
|
||||||
durable=True,
|
durable=True,
|
||||||
auto_delete=False)
|
auto_delete=False)
|
||||||
queue = channel.queue_declare(durable=True, auto_delete=False)
|
queue = channel.queue_declare(durable=True, auto_delete=False, queue=uuid.uuid4().urn.split(':')[2],
|
||||||
queue.bind(exchange)
|
exclusive=True).method.queue
|
||||||
queue.basic_consume(on_message, no_ack=True)
|
channel.queue_bind(exchange=config.RABBIT_EXCHANGE, queue=queue)
|
||||||
|
channel.basic_consume(queue=queue, on_message_callback=on_message, auto_ack=True)
|
||||||
|
|
||||||
|
|
||||||
def on_message(channel, method_frame, header_frame, body):
|
def on_message(channel, method_frame, header_frame, body):
|
||||||
|
Loading…
Reference in New Issue
Block a user