parent
b04dfeda4c
commit
043ee029d2
@ -0,0 +1,37 @@
|
|||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
from config.celery import app
|
||||||
|
from djconfig import config
|
||||||
|
|
||||||
|
|
||||||
|
@app.task(bind=True)
|
||||||
|
def upload_image_rpc(self, queued_image_pk, fpath, caption):
|
||||||
|
from .modules.channel_helper import QueuedItem
|
||||||
|
try:
|
||||||
|
logging.warning(f'Processing upload task for queued item #{queued_image_pk}')
|
||||||
|
qi = QueuedItem.objects.get(pk=queued_image_pk)
|
||||||
|
bot = qi.config.bot.get_bot()
|
||||||
|
if qi.config.queued:
|
||||||
|
m = bot.send_photo(
|
||||||
|
config.tmp_uploads_chat_id,
|
||||||
|
open(fpath, 'rb'),
|
||||||
|
caption=caption,
|
||||||
|
)
|
||||||
|
qi.message_id = m.message_id
|
||||||
|
qi.args = json.dumps([m.photo[-1].file_id])
|
||||||
|
qi.save()
|
||||||
|
else:
|
||||||
|
bot.send_photo(
|
||||||
|
qi.config.chat_id,
|
||||||
|
open(fpath, 'rb'),
|
||||||
|
caption=caption,
|
||||||
|
)
|
||||||
|
qi.processed = True
|
||||||
|
qi.save()
|
||||||
|
os.unlink(fpath)
|
||||||
|
except Exception as e:
|
||||||
|
traceback.print_exc()
|
||||||
|
raise self.retry(exc=e, countdown=5)
|
Loading…
Reference in new issue