From fd874b4cd83a5425486d5584e1e62548f637e77b Mon Sep 17 00:00:00 2001 From: Dantenerosas Date: Tue, 26 Sep 2023 16:32:36 +0300 Subject: [PATCH] minor fixes --- src/core/master_service.py | 1 + src/core/redis_client.py | 5 +++++ src/web/main.py | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/master_service.py b/src/core/master_service.py index 3ec13d3..217886a 100644 --- a/src/core/master_service.py +++ b/src/core/master_service.py @@ -42,6 +42,7 @@ class MasterService: while True: video_params = await self.queue.get() redis = RedisClient() + await redis.del_tasks_queue() await redis.del_task_from_queue_and_add_to_tasks(task=video_params) self.currently_underway[video_params['link']] = video_params diff --git a/src/core/redis_client.py b/src/core/redis_client.py index 0ca8ad3..b1285ed 100644 --- a/src/core/redis_client.py +++ b/src/core/redis_client.py @@ -60,3 +60,8 @@ class RedisClient: async with self.connection as connection: res = await connection.srem(self.TASKS_DONE_NAME + f":1", json.dumps(task, indent=4).encode('utf-8')) return res + + async def del_tasks_queue(self) -> int: + async with self.connection as connection: + res = await connection.delete(self.TASKS_NAME + f":1") + return res diff --git a/src/web/main.py b/src/web/main.py index b9223bd..fa57ce6 100644 --- a/src/web/main.py +++ b/src/web/main.py @@ -71,7 +71,9 @@ async def is_task_already_done_or_exist(redis: RedisClient, link: str): if len(tasks) > 0: task = tasks[0] - return task + if os.path.exists(os.path.join(os.getcwd(), os.pardir, os.pardir + "/downloads/" + task["result"])): + return task + await redis.del_task_from_task_done_queue(task) async def is_task_in_process(redis: RedisClient, link: str): @@ -145,7 +147,7 @@ async def download_video(file_path): with open(base_download_dir + f'/{file_path}', mode="rb") as file_like: yield from file_like - return StreamingResponse(iterfile(), media_type="video/mp4") + return StreamingResponse(iterfile(), headers={'Content-Disposition': f'inline; filename="{file_path}"'}, media_type="video") @app.post('/check/', response_class=FileResponse, status_code=200)