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:
		
							
								
								
									
										25
									
								
								src/app.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								src/app.py
									
									
									
									
									
								
							@@ -1,9 +1,14 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
import json
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
import sentry_sdk
 | 
			
		||||
import pika
 | 
			
		||||
import requests
 | 
			
		||||
from sentry_sdk.integrations.logging import LoggingIntegration
 | 
			
		||||
 | 
			
		||||
import config
 | 
			
		||||
import uuid
 | 
			
		||||
from mqtt_helper import MQTT
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
@@ -16,9 +21,14 @@ __module_name__ = "app"
 | 
			
		||||
__version__text__ = "1"
 | 
			
		||||
 | 
			
		||||
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(
 | 
			
		||||
        dsn=config.SENTRY_DSN,
 | 
			
		||||
        send_default_pii=True,
 | 
			
		||||
        integrations=[sentry_logging],
 | 
			
		||||
        release=config.RELEASE_ID,
 | 
			
		||||
        environment=config.RELEASEMODE
 | 
			
		||||
    )
 | 
			
		||||
@@ -31,13 +41,14 @@ def setup_rabbit() -> None:
 | 
			
		||||
                                                                   heartbeat=0,
 | 
			
		||||
                                                                   socket_timeout=5))
 | 
			
		||||
    channel = connection.channel()
 | 
			
		||||
    exchange = channel.exchange_declare(exchange=config.RABBIT_EXCHANGE,
 | 
			
		||||
                                        exchange_type='fanout',
 | 
			
		||||
                                        durable=True,
 | 
			
		||||
                                        auto_delete=False)
 | 
			
		||||
    queue = channel.queue_declare(durable=True, auto_delete=False)
 | 
			
		||||
    queue.bind(exchange)
 | 
			
		||||
    queue.basic_consume(on_message, no_ack=True)
 | 
			
		||||
    channel.exchange_declare(exchange=config.RABBIT_EXCHANGE,
 | 
			
		||||
                             exchange_type='fanout',
 | 
			
		||||
                             durable=True,
 | 
			
		||||
                             auto_delete=False)
 | 
			
		||||
    queue = channel.queue_declare(durable=True, auto_delete=False, 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, auto_ack=True)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def on_message(channel, method_frame, header_frame, body):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user