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) progress_message= "{0} % ({1} / {2})".format(percentage, received, total)
in_progress[filename] = progress_message in_progress[filename] = progress_message
# if (int(percentage) % 5) == 0: if (int(percentage) % 5) == 0:
# await log_reply(message, progress_message) await log_reply(message, progress_message)
with TelegramClient(getSession(), api_id, api_hash, with TelegramClient(getSession(), api_id, api_hash,
@ -140,6 +140,8 @@ with TelegramClient(getSession(), api_id, api_hash,
print(event) print(event)
try:
if not event.media and event.message: if not event.media and event.message:
command = event.message.message command = event.message.message
command = command.lower() command = command.lower()
@ -168,10 +170,12 @@ with TelegramClient(getSession(), api_id, api_hash,
filename=getFilename(event) filename=getFilename(event)
message=await event.reply("{0} added to queue".format(filename)) message=await event.reply("{0} added to queue".format(filename))
await queue.put([event, message]) await queue.put([event, message])
except Exception as e:
print('Events handler error: ', e)
async def worker(): async def worker():
while True: while True:
try:
element = await queue.get() element = await queue.get()
event=element[0] event=element[0]
message=element[1] 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) 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) 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)) await log_reply(message, "{0} ready".format(filename))
queue.task_done() queue.task_done()
except Exception as e:
print('Queue worker error: ', e)
async def start(): async def start():
tasks = [] tasks = []