Mbonea commited on
Commit
4b7d88e
1 Parent(s): d3069fb

added some async code stabilize pyrogram

Browse files
Files changed (2) hide show
  1. App/Worker.py +8 -2
  2. requirements.txt +1 -0
App/Worker.py CHANGED
@@ -6,7 +6,7 @@ from App import celery_config, bot
6
  from typing import List
7
  from App.Editor.Schema import EditorRequest, LinkInfo
8
  from celery.signals import worker_process_init
9
-
10
 
11
  celery = Celery()
12
  celery.config_from_object(celery_config)
@@ -70,8 +70,14 @@ def render_video(directory: str, output_directory: str):
70
  def cleanup_temp_directory(
71
  temp_dir: str, output_dir: str, chat_id: int = -1002069945904
72
  ):
 
 
 
 
73
  try:
74
- bot.send_video(-1002069945904, video=output_dir, caption="Your video caption")
 
 
75
  finally:
76
  # Cleanup: Remove the temporary directory
77
  shutil.rmtree(temp_dir, ignore_errors=True)
 
6
  from typing import List
7
  from App.Editor.Schema import EditorRequest, LinkInfo
8
  from celery.signals import worker_process_init
9
+ from asgiref.sync import async_to_sync
10
 
11
  celery = Celery()
12
  celery.config_from_object(celery_config)
 
70
  def cleanup_temp_directory(
71
  temp_dir: str, output_dir: str, chat_id: int = -1002069945904
72
  ):
73
+ async_to_sync(SendVideo(temp_dir, output_dir, chat_id=-1002069945904))
74
+
75
+
76
+ async def SendVideo(temp_dir: str, output_dir: str, chat_id: int = -1002069945904):
77
  try:
78
+ await bot.send_video(
79
+ -1002069945904, video=output_dir, caption="Your video caption"
80
+ )
81
  finally:
82
  # Cleanup: Remove the temporary directory
83
  shutil.rmtree(temp_dir, ignore_errors=True)
requirements.txt CHANGED
@@ -23,3 +23,4 @@ python-multipart
23
  git+https://github.com/redis/redis-py.git
24
  TgCrypto
25
  pyrogram==2.0.100
 
 
23
  git+https://github.com/redis/redis-py.git
24
  TgCrypto
25
  pyrogram==2.0.100
26
+ asgiref