2020-03-30 01:26:45 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import pika
|
2020-03-30 20:40:14 +02:00
|
|
|
import json
|
|
|
|
|
2020-04-19 21:45:26 +02:00
|
|
|
from sentry_sdk.integrations.logging import LoggingIntegration
|
|
|
|
import sentry_sdk
|
|
|
|
|
2020-03-30 20:40:14 +02:00
|
|
|
from extraction import run_everything
|
2020-03-30 01:26:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
def message_callback(ch, method, properties, body):
|
2020-03-30 20:40:14 +02:00
|
|
|
run_everything(json.loads(body.decode('utf-8')))
|
2020-03-30 01:26:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
logging.basicConfig(filename="", format="%(asctime)s - %(name)s [%(levelname)s]: %(message)s",
|
|
|
|
level=logging.DEBUG if '--debug' in sys.argv else logging.INFO)
|
|
|
|
|
2020-04-19 21:45:26 +02:00
|
|
|
SENTRY_DSN = os.environ.get("SENTRY_DSN")
|
|
|
|
if 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,
|
|
|
|
integrations=[sentry_logging],
|
|
|
|
send_default_pii=True,
|
|
|
|
release=os.environ.get('RELEASE_ID', 'test'),
|
|
|
|
environment=os.environ.get('RELEASEMODE', 'dev')
|
|
|
|
)
|
|
|
|
|
2020-03-30 20:40:14 +02:00
|
|
|
logging.info("Connecting to MQ service...")
|
2020-03-30 01:26:45 +02:00
|
|
|
connection = pika.BlockingConnection(pika.connection.URLParameters(os.environ['PIKA_URL']))
|
|
|
|
channel = connection.channel()
|
|
|
|
channel.exchange_declare(exchange='wave-extract', exchange_type='fanout')
|
|
|
|
|
|
|
|
queue_declare_result = channel.queue_declare(queue='', exclusive=True)
|
|
|
|
queue_name = queue_declare_result.method.queue
|
|
|
|
|
2020-04-29 23:30:07 +02:00
|
|
|
channel.queue_bind(exchange=os.environ['PIKA_EXCHANGE_NAME'], queue=queue_name)
|
2020-03-30 01:26:45 +02:00
|
|
|
channel.basic_consume(queue=queue_name, on_message_callback=message_callback, auto_ack=True)
|
|
|
|
|
2020-03-30 20:40:14 +02:00
|
|
|
logging.info("Connection complete! Listening to messages...")
|
2020-03-30 01:26:45 +02:00
|
|
|
try:
|
|
|
|
channel.start_consuming()
|
|
|
|
except KeyboardInterrupt:
|
2020-03-30 20:40:14 +02:00
|
|
|
logging.info("SIGINT Received! Stopping stuff...")
|
2020-03-30 01:26:45 +02:00
|
|
|
channel.stop_consuming()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|