fix
This commit is contained in:
parent
add2c9597a
commit
d5ed758605
@ -24,13 +24,14 @@ class Feed(models.Model):
|
|||||||
|
|
||||||
def run_check(self):
|
def run_check(self):
|
||||||
if self.lock:
|
if self.lock:
|
||||||
return
|
return False
|
||||||
if self.last_check and timezone.now() < self.last_check + self.check_interval:
|
if self.last_check and timezone.now() < self.last_check + self.check_interval:
|
||||||
return
|
return False
|
||||||
|
|
||||||
self.lock = True
|
self.lock = True
|
||||||
self.save()
|
self.save()
|
||||||
execute_feed.apply_async(args=(self.pk,), shadow=str(self))
|
execute_feed.apply_async(args=(self.pk,), shadow=str(self))
|
||||||
|
return True
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'#{self.pk} {self.title}'
|
return f'#{self.pk} {self.title}'
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
|
from celery.exceptions import Reject
|
||||||
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
|
||||||
@ -12,8 +13,11 @@ def check_feeds():
|
|||||||
from feeds.models import Feed
|
from feeds.models import Feed
|
||||||
|
|
||||||
feeds = Feed.objects.filter(lock=False)
|
feeds = Feed.objects.filter(lock=False)
|
||||||
|
enqueued = []
|
||||||
for feed in feeds:
|
for feed in feeds:
|
||||||
feed.run_check()
|
if feed.run_check():
|
||||||
|
enqueued.append(str(feed))
|
||||||
|
return f'Following tasks were enqueued: {enqueued}'
|
||||||
|
|
||||||
|
|
||||||
@app.task()
|
@app.task()
|
||||||
@ -25,14 +29,12 @@ 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:
|
else:
|
||||||
print(f'Lock detected, aborting "{feed}"...')
|
raise Reject('Lock', requeue=False)
|
||||||
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}"')
|
print(f'Last ID for "{feed}" = "{feed.last_id}"')
|
||||||
@ -46,6 +48,7 @@ def execute_feed(feed_pk):
|
|||||||
feed.save()
|
feed.save()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sentry_sdk.capture_exception(e)
|
sentry_sdk.capture_exception(e)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
if feed:
|
if feed:
|
||||||
feed.lock = False
|
feed.lock = False
|
||||||
|
Loading…
Reference in New Issue
Block a user