Skip to content

Commit

Permalink
Minor changes nd fix
Browse files Browse the repository at this point in the history
Fix dead lock

Signed-off-by: anasty17 <e.anastayyar@gmail.com>
  • Loading branch information
anasty17 committed Nov 8, 2023
1 parent e89cf01 commit 350e0bf
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
15 changes: 6 additions & 9 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,10 @@ async def proceedExtract(self, dl_path, size, gid):
self.suproc = await create_subprocess_exec(*cmd)
_, stderr = await self.suproc.communicate()
code = self.suproc.returncode
stderr = stderr.decode().strip()
if code == -9:
return False
elif code != 0:
stderr = stderr.decode().strip()
LOGGER.error(
f"{stderr}. Unable to extract archive splits!. Path: {f_path}"
)
Expand Down Expand Up @@ -465,7 +465,6 @@ async def proceedExtract(self, dl_path, size, gid):
self.suproc = await create_subprocess_exec(*cmd)
_, stderr = await self.suproc.communicate()
code = self.suproc.returncode
stderr = stderr.decode().strip()
if code == -9:
return False
elif code == 0:
Expand All @@ -477,6 +476,7 @@ async def proceedExtract(self, dl_path, size, gid):
return False
return up_path
else:
stderr = stderr.decode().strip()
LOGGER.error(
f"{stderr}. Unable to extract archive! Uploading anyway. Path: {dl_path}"
)
Expand Down Expand Up @@ -530,14 +530,14 @@ async def proceedCompress(self, dl_path, size, gid):
self.suproc = await create_subprocess_exec(*cmd)
_, stderr = await self.suproc.communicate()
code = self.suproc.returncode
stderr = stderr.decode().strip()
if code == -9:
return False
elif code == 0:
if not self.seed:
await clean_target(dl_path)
return up_path
else:
stderr = stderr.decode().strip()
LOGGER.error(f"{stderr}. Unable to zip this path: {dl_path}")
return dl_path

Expand Down Expand Up @@ -584,14 +584,15 @@ async def generateSampleVideo(self, dl_path, size, gid):
sample_duration = 60
part_duration = 4

async with task_dict_lock:
task_dict[self.mid] = SampleVideoStatus(self, size, gid)

async with cpu_eater_lock:
checked = False
if await aiopath.isfile(dl_path):
if (await get_document_type(dl_path))[0]:
if not checked:
checked = True
async with task_dict_lock:
task_dict[self.mid] = SampleVideoStatus(self, size, gid)
LOGGER.info(f"Creating Sample video: {self.name}")
res = await createSampleVideo(
self, dl_path, sample_duration, part_duration, True
Expand All @@ -606,10 +607,6 @@ async def generateSampleVideo(self, dl_path, size, gid):
if (await get_document_type(f_path))[0]:
if not checked:
checked = True
async with task_dict_lock:
task_dict[self.mid] = SampleVideoStatus(
self, size, gid
)
LOGGER.info(f"Creating Sample videos: {self.name}")
res = await createSampleVideo(
self, f_path, sample_duration, part_duration
Expand Down
8 changes: 4 additions & 4 deletions bot/helper/ext_utils/media_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ async def split_file(
listener.suproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.suproc.communicate()
code = listener.suproc.returncode
stderr = stderr.decode().strip()
if code == -9:
return False
elif code != 0:
stderr = stderr.decode().strip()
try:
await aioremove(out_path)
except:
Expand Down Expand Up @@ -350,10 +350,10 @@ async def split_file(
)
_, stderr = await listener.suproc.communicate()
code = listener.suproc.returncode
stderr = stderr.decode().strip()
if code == -9:
return False
elif code != 0:
stderr = stderr.decode().strip()
LOGGER.error(f"{stderr}. Split Document: {path}")
return True

Expand Down Expand Up @@ -414,12 +414,12 @@ async def createSampleVideo(
listener.suproc = await create_subprocess_exec(*cmd, stderr=PIPE)
_, stderr = await listener.suproc.communicate()
code = listener.suproc.returncode
stderr = stderr.decode().strip()
if code == -9:
return False
elif code != 0:
stderr = stderr.decode().strip()
LOGGER.error(
f"Something went wrong while creating sample video, mostly file is corrupted. Path: {input_file}"
f"{stderr}. Something went wrong while creating sample video, mostly file is corrupted. Path: {input_file}"
)
return input_file
else:
Expand Down
6 changes: 3 additions & 3 deletions bot/helper/ext_utils/status_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_progress_bar_string(pct):
return f"[{p_str}]"


def get_readable_message(sid, is_user, page_no=1, status="All"):
def get_readable_message(sid, is_user, page_no=1, status="All", page_step=1):
msg = ""
button = None

Expand Down Expand Up @@ -167,10 +167,10 @@ def get_readable_message(sid, is_user, page_no=1, status="All"):
if not is_user:
buttons.ibutton("📜", "status 0 ov", position="header")
if len(tasks) > STATUS_LIMIT:
msg += f"<b>Page:</b> {page_no}/{pages} | <b>Tasks:</b> {tasks_no}\n"
msg += f"<b>Page:</b> {page_no}/{pages} | <b>Tasks:</b> {tasks_no} | <b>Step:</b> {page_step}\n"
buttons.ibutton("<<", f"status {sid} pre", position="header")
buttons.ibutton(">>", f"status {sid} nex", position="header")
if tasks_no > 20:
if tasks_no > 30:
for i in [1, 2, 4, 6, 8, 10, 15, 20]:
buttons.ibutton(i, f"status {sid} ps {i}", position="footer")
if len(task_dict) > STATUS_LIMIT or status != "All":
Expand Down
6 changes: 4 additions & 2 deletions bot/helper/telegram_helper/message_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ async def update_status_message(sid, force=False):
page_no = status_dict[sid]["page_no"]
status = status_dict[sid]["status"]
is_user = status_dict[sid]["is_user"]
page_step = status_dict[sid]["page_step"]
text, buttons = await sync_to_async(
get_readable_message, sid, is_user, page_no, status
get_readable_message, sid, is_user, page_no, status, page_step
)
if text is None:
del status_dict[sid]
Expand Down Expand Up @@ -224,8 +225,9 @@ async def sendStatusMessage(msg, user_id=0):
if sid in list(status_dict.keys()):
page_no = status_dict[sid]["page_no"]
status = status_dict[sid]["status"]
page_step = status_dict[sid]["page_step"]
text, buttons = await sync_to_async(
get_readable_message, sid, is_user, page_no, status
get_readable_message, sid, is_user, page_no, status, page_step
)
if text is None:
del status_dict[sid]
Expand Down
4 changes: 3 additions & 1 deletion bot/modules/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ async def status_pages(_, query):
EX: {tasks['Extract']} | SP: {tasks['Split']} | QD: {tasks['QueueDl']} | QU: {tasks['QueueUp']}
CL: {tasks['Clone']} | CH: {tasks['CheckUp']} | PA:{tasks['Pause']}
DLS: {get_readable_file_size(dl_speed)}/s | ULS: {get_readable_file_size(up_speed)}/s | SDS: {get_readable_file_size(seed_speed)}/s
ODLS: {get_readable_file_size(dl_speed)}/s
OULS: {get_readable_file_size(up_speed)}/s
OSDS: {get_readable_file_size(seed_speed)}/s
"""
await query.answer(msg, show_alert=True)

Expand Down

0 comments on commit 350e0bf

Please sign in to comment.