log errors but don't fail
This commit is contained in:
parent
41c1b1cdec
commit
9f446139be
1 changed files with 22 additions and 14 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
|
@ -12,6 +13,7 @@ from ..telegrambot import rpc as telegram_rpc
|
||||||
from ..celery import app
|
from ..celery import app
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@app.task(queue="default", ignore_results=True)
|
@app.task(queue="default", ignore_results=True)
|
||||||
def announce_items():
|
def announce_items():
|
||||||
|
|
@ -32,21 +34,27 @@ def announce_items():
|
||||||
f.close()
|
f.close()
|
||||||
image = f.name
|
image = f.name
|
||||||
if getattr(settings, "SIGNAL_ANNOUNCE_GROUP"):
|
if getattr(settings, "SIGNAL_ANNOUNCE_GROUP"):
|
||||||
r = rpc.send(
|
try:
|
||||||
message,
|
r = rpc.send(
|
||||||
group=settings.SIGNAL_ANNOUNCE_GROUP,
|
message,
|
||||||
preview_url=link,
|
group=settings.SIGNAL_ANNOUNCE_GROUP,
|
||||||
preview_title=item.title,
|
preview_url=link,
|
||||||
preview_image=image,
|
preview_title=item.title,
|
||||||
preview_description=description,
|
preview_image=image,
|
||||||
)
|
preview_description=description,
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
logger.error("failed to send singal", exec_info=True)
|
||||||
if getattr(settings, "TELEGRAM_ANNOUNCE_CHANNEL"):
|
if getattr(settings, "TELEGRAM_ANNOUNCE_CHANNEL"):
|
||||||
message = f'{item.title}\n<a href="{link}">{link}</a>'
|
try:
|
||||||
r = telegram_rpc.send(
|
message = f'{item.title}\n<a href="{link}">{link}</a>'
|
||||||
message,
|
r = telegram_rpc.send(
|
||||||
channel=settings.TELEGRAM_ANNOUNCE_CHANNEL,
|
message,
|
||||||
preview_image=image,
|
channel=settings.TELEGRAM_ANNOUNCE_CHANNEL,
|
||||||
)
|
preview_image=image,
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
logger.error("failed to send telegram", exec_info=True)
|
||||||
item.save()
|
item.save()
|
||||||
if image:
|
if image:
|
||||||
os.unlink(f.name)
|
os.unlink(f.name)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue