From 6a0ed2c7dcc015c9c0089a28222c0dfd11c25b12 Mon Sep 17 00:00:00 2001 From: Daneryl Date: Fri, 15 Jul 2022 11:43:27 +0200 Subject: [PATCH] add sentry config --- docker-compose.yml | 3 +++ requirements.txt | 3 ++- src/QueueProcessor.py | 17 ++++++++++++++++- src/data/Params.py | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index bd057fd..d939549 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,9 @@ services: volumes: - ./docker_volume:/app/docker_volume profiles: ['production', 'testing'] + environment: + - ENVIRONMENT=${ENVIRONMENT:-development} + - SENTRY_DSN=${SENTRY_DSN:-} mongo_twitter: network_mode: host restart: unless-stopped diff --git a/requirements.txt b/requirements.txt index e486c0e..f5392e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,5 @@ redis~=3.5.3 pytest black tweepy~=4.5.0 -pymongo~=4.0.2 \ No newline at end of file +pymongo~=4.0.2 +sentry-sdk diff --git a/src/QueueProcessor.py b/src/QueueProcessor.py index 626ed4f..cdd32f0 100644 --- a/src/QueueProcessor.py +++ b/src/QueueProcessor.py @@ -1,3 +1,4 @@ +import os from datetime import datetime, timezone from time import sleep from typing import List @@ -9,15 +10,19 @@ from pydantic import ValidationError from rsmq.consumer import RedisSMQConsumer from rsmq import RedisSMQ +from sentry_sdk.integrations.redis import RedisIntegration +import sentry_sdk from ServiceConfig import ServiceConfig from data.Task import Task from data.TweetData import TweetData from data.TweetMessage import TweetMessage + class UserSuspended(Exception): pass + class QueueProcessor: TIME_BETWEEN_QUERIES_IN_MINUTES = 4 @@ -98,7 +103,7 @@ def get_tweepy_query_params(self, task): if task.params.query[0] == "@": tweepy_client = tweepy.Client(self.service_config.twitter_bearer_token) user = tweepy_client.get_user(username=task.params.query[1:]) - if user.errors and 'detail' in user.errors[0] and 'suspended' in user.errors[0]['detail']: + if user.errors and "detail" in user.errors[0] and "suspended" in user.errors[0]["detail"]: raise UserSuspended tweepy_params["id"] = user.data["id"] @@ -169,5 +174,15 @@ def get_sanitized_query(query): if __name__ == "__main__": + try: + sentry_sdk.init( + os.environ.get("SENTRY_DSN"), + traces_sample_rate=0.1, + environment=os.environ.get("ENVIRONMENT", "development"), + integrations=[RedisIntegration()], + ) + except Exception: + pass + redis_tasks_processor = QueueProcessor() redis_tasks_processor.subscribe_to_extractions_tasks_queue() diff --git a/src/data/Params.py b/src/data/Params.py index 1b8e639..ab89554 100644 --- a/src/data/Params.py +++ b/src/data/Params.py @@ -5,4 +5,4 @@ class Params(BaseModel): query: str - tweets_languages: List[str] = list() \ No newline at end of file + tweets_languages: List[str] = list()