pmrony commited on
Commit
ce40100
·
verified ·
1 Parent(s): 0f1a29e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -65,6 +65,10 @@ except RuntimeError:
65
  main_loop = asyncio.new_event_loop()
66
  asyncio.set_event_loop(main_loop)
67
 
 
 
 
 
68
  bot = Client("file_unlocker_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
69
 
70
  # ==================== ROBUST DB QUERY WITH AUTO-RETRY ====================
@@ -1196,7 +1200,7 @@ async def watermark_processor_loop():
1196
  print(f"❌ Redis Connection Failed in Hugging Face: {e}")
1197
  return
1198
 
1199
- # সার্ভার রিস্টার্ট হলে আটকে থাকা লকগুলো ক্লিয়ার করবে
1200
  try:
1201
  async for key in redis_client.scan_iter("wm_processing:*"):
1202
  await redis_client.delete(key)
@@ -1208,7 +1212,6 @@ async def watermark_processor_loop():
1208
  await asyncio.sleep(2)
1209
  continue
1210
 
1211
- # BRPOP এর বদলে RPOP ব্যবহার করা হলো (Upstash Connection Drop এড়াতে)
1212
  result = await redis_client.rpop("watermark_task_queue")
1213
 
1214
  if result:
@@ -1219,7 +1222,7 @@ async def watermark_processor_loop():
1219
  processing_owners.add(owner_id)
1220
  asyncio.create_task(process_single_video(task, redis_client))
1221
  else:
1222
- await asyncio.sleep(2) # ভিডিও না থাকলে ২ সেকেন্ড পর আবার চেক করবে
1223
 
1224
  except Exception as e:
1225
  print(f"❌ [WM] Loop Error: {e}")
@@ -1243,4 +1246,5 @@ async def main():
1243
 
1244
  if __name__ == "__main__":
1245
  threading.Thread(target=run_flask, daemon=True).start()
1246
- main_loop.run_until_complete(main())
 
 
65
  main_loop = asyncio.new_event_loop()
66
  asyncio.set_event_loop(main_loop)
67
 
68
+ def run_async(coro):
69
+ future = asyncio.run_coroutine_threadsafe(coro, main_loop)
70
+ return future.result()
71
+
72
  bot = Client("file_unlocker_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
73
 
74
  # ==================== ROBUST DB QUERY WITH AUTO-RETRY ====================
 
1200
  print(f"❌ Redis Connection Failed in Hugging Face: {e}")
1201
  return
1202
 
1203
+ # Clear stuck locks
1204
  try:
1205
  async for key in redis_client.scan_iter("wm_processing:*"):
1206
  await redis_client.delete(key)
 
1212
  await asyncio.sleep(2)
1213
  continue
1214
 
 
1215
  result = await redis_client.rpop("watermark_task_queue")
1216
 
1217
  if result:
 
1222
  processing_owners.add(owner_id)
1223
  asyncio.create_task(process_single_video(task, redis_client))
1224
  else:
1225
+ await asyncio.sleep(2)
1226
 
1227
  except Exception as e:
1228
  print(f"❌ [WM] Loop Error: {e}")
 
1246
 
1247
  if __name__ == "__main__":
1248
  threading.Thread(target=run_flask, daemon=True).start()
1249
+ main_loop.run_until_complete(main())
1250
+ #--- END OF FILE main.py