Verbose feed logging

This commit is contained in:
bakatrouble 2019-03-10 10:11:59 +03:00
parent a24ab2dcf0
commit 83d752c1a2
2 changed files with 10 additions and 1 deletions

View File

@ -33,7 +33,7 @@ class Feed(models.Model):
execute_feed.delay(self.pk) execute_feed.delay(self.pk)
def __str__(self): def __str__(self):
return self.title return f'#{self.pk} {self.title}'
class Meta: class Meta:
unique_together = ('config_type', 'config_id') unique_together = ('config_type', 'config_id')

View File

@ -1,3 +1,4 @@
import sentry_sdk
from celery_once import QueueOnce from celery_once import QueueOnce
from django.utils import timezone from django.utils import timezone
from telebot import TeleBot from telebot import TeleBot
@ -24,19 +25,27 @@ def execute_feed(feed_pk):
feed = None feed = None
try: try:
feed = Feed.objects.get(pk=feed_pk) feed = Feed.objects.get(pk=feed_pk)
print(f'Processing feed "{feed}"')
if not feed.lock: if not feed.lock:
feed.lock = True feed.lock = True
feed.save() feed.save()
else:
print(f'Lock detected, aborting "{feed}"...')
return
bot = TeleBot(config.feed_bot_token, threaded=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): for last_id in feed.config.execute(bot, feed.chat_id, feed.last_id):
if last_id: if last_id:
feed.last_id = last_id feed.last_id = last_id
feed.save() feed.save()
print(f'Saved last ID for "{feed}" = "{feed.last_id}"')
bot.stop_bot() bot.stop_bot()
feed.last_check = timezone.now() feed.last_check = timezone.now()
feed.save() feed.save()
except Exception as e:
sentry_sdk.capture_exception(e)
finally: finally:
if feed: if feed:
feed.lock = False feed.lock = False