From 32f5c457e538a9b8d9f1581721288a0505b42565 Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Thu, 11 Apr 2019 02:07:37 +0300 Subject: [PATCH] add tags for sentry --- feeds/tasks.py | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/feeds/tasks.py b/feeds/tasks.py index b50b8ee..25e8cac 100644 --- a/feeds/tasks.py +++ b/feeds/tasks.py @@ -28,29 +28,24 @@ def execute_feed(feed_pk): config._reload_maybe() - feed = None - try: - feed = Feed.objects.get(pk=feed_pk) + feed = Feed.objects.get(pk=feed_pk) - # if not feed.lock: - # feed.lock = True - # feed.save() - # else: - # raise Reject('Lock', requeue=False) - - bot = TeleBot(config.feed_bot_token, threaded=False) - print(f'Last ID for "{feed}" = "{feed.last_id}"') - for last_id in feed.config.execute(bot, feed.chat_id, feed.last_id): - if last_id: - feed.last_id = last_id - feed.save() - print(f'Saved last ID for "{feed}" = "{feed.last_id}"') - feed.last_check = timezone.now() - feed.save() - except Exception as e: - sentry_sdk.capture_exception(e) - traceback.print_exc() - finally: - if feed: - feed.lock = False + with sentry_sdk.configure_scope() as scope: + scope.set_extra('feed', str(feed)) + try: + bot = TeleBot(config.feed_bot_token, threaded=False) + print(f'Last ID for "{feed}" = "{feed.last_id}"') + for last_id in feed.config.execute(bot, feed.chat_id, feed.last_id): + if last_id: + feed.last_id = last_id + feed.save() + print(f'Saved last ID for "{feed}" = "{feed.last_id}"') + feed.last_check = timezone.now() feed.save() + except Exception as e: + sentry_sdk.capture_exception(e) + traceback.print_exc() + finally: + if feed: + feed.lock = False + feed.save()