Separated config

This commit is contained in:
2021-07-30 11:43:38 +02:00
parent bcbc69e00f
commit aa2cc0214c
4 changed files with 34 additions and 19 deletions

View File

@@ -9,6 +9,8 @@ from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk import start_transaction
import sentry_sdk
from config import Config
from magic_doer import MagicDoer
@@ -24,7 +26,7 @@ def message_callback(channel, method, properties, body):
if results:
channel.basic_publish(
exchange=os.environ['PIKA_OUTPUT_EXCHANGE'],
exchange=Config.PIKA_OUTPUT_EXCHANGE,
routing_key='classification-result',
body=json.dumps(results).encode("utf-8")
)
@@ -38,31 +40,30 @@ def main():
level=logging.DEBUG if '--debug' in sys.argv else logging.INFO
)
SENTRY_DSN = os.environ.get("SENTRY_DSN")
if 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(
dsn=SENTRY_DSN,
dsn=Config.SENTRY_DSN,
integrations=[sentry_logging],
traces_sample_rate=1.0,
send_default_pii=True,
release=os.environ.get('RELEASE_ID', 'test'),
environment=os.environ.get('RELEASEMODE', 'dev'),
release=Config.RELEASE_ID,
environment=Config.RELEASEMODE,
_experiments={"auto_enabling_integrations": True}
)
logging.info("Connecting to MQ service...")
connection = pika.BlockingConnection(pika.connection.URLParameters(os.environ['PIKA_URL']))
connection = pika.BlockingConnection(pika.connection.URLParameters(Config.PIKA_URL))
channel = connection.channel()
channel.exchange_declare(exchange=os.environ['PIKA_INPUT_EXCHANGE'], exchange_type='direct')
channel.exchange_declare(exchange=Config.PIKA_INPUT_EXCHANGE, exchange_type='direct')
queue_declare_result = channel.queue_declare(queue='cnnqueue', exclusive=False)
queue_name = queue_declare_result.method.queue
channel.queue_bind(exchange=os.environ['PIKA_INPUT_EXCHANGE'], routing_key='feature', queue=queue_name)
channel.queue_bind(exchange=Config.PIKA_INPUT_EXCHANGE, routing_key='feature', queue=queue_name)
channel.basic_qos(prefetch_count=1)