Improved error control

This commit is contained in:
Alfonso E.M 2021-02-21 14:58:39 +01:00
parent c920632227
commit 7532edc2e7

View file

@ -120,8 +120,8 @@ async def set_progress(filename, message, received, total):
progress_message= "{0} % ({1} / {2})".format(percentage, received, total)
in_progress[filename] = progress_message
# if (int(percentage) % 5) == 0:
# await log_reply(message, progress_message)
if (int(percentage) % 5) == 0:
await log_reply(message, progress_message)
with TelegramClient(getSession(), api_id, api_hash,
@ -140,6 +140,8 @@ with TelegramClient(getSession(), api_id, api_hash,
print(event)
try:
if not event.media and event.message:
command = event.message.message
command = command.lower()
@ -168,10 +170,12 @@ with TelegramClient(getSession(), api_id, api_hash,
filename=getFilename(event)
message=await event.reply("{0} added to queue".format(filename))
await queue.put([event, message])
except Exception as e:
print('Events handler error: ', e)
async def worker():
while True:
try:
element = await queue.get()
event=element[0]
message=element[1]
@ -187,10 +191,12 @@ with TelegramClient(getSession(), api_id, api_hash,
await client.download_media(event.message, "{0}/{1}.{2}".format(tempFolder,filename,TELEGRAM_DAEMON_TEMP_SUFFIX), progress_callback = download_callback)
set_progress(filename, message, 100, 100)
rename("{0}/{1}.{2}".format(temFolder,filename,TELEGRAM_DAEMON_TEMP_SUFFIX), "{0}/{1}".format(downloadFolder,filename))
rename("{0}/{1}.{2}".format(tempFolder,filename,TELEGRAM_DAEMON_TEMP_SUFFIX), "{0}/{1}".format(downloadFolder,filename))
await log_reply(message, "{0} ready".format(filename))
queue.task_done()
except Exception as e:
print('Queue worker error: ', e)
async def start():
tasks = []