seawolf2357 commited on
Commit
b183030
β€’
1 Parent(s): da8c445

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -174,21 +174,32 @@ async def generate_replies(comments, transcript):
174
  logging.debug(f'μƒμ„±λœ λ‹΅κΈ€: {replies}')
175
  return replies
176
 
 
 
177
  async def send_webhook_data(session, chunk_data, chunk_number):
178
- for attempt in range(MAX_RETRIES):
 
 
 
179
  try:
180
- async with session.post(WEBHOOK_URL, json=chunk_data) as resp:
181
- if resp.status == 200:
182
- logging.info(f"μ›Ήν›…μœΌλ‘œ 데이터 전솑 성곡: {chunk_number} 번째 μ‹œλ„")
183
  return True # 성곡 μ‹œ μ’…λ£Œ
184
  else:
185
- logging.error(f"μ›Ήν›…μœΌλ‘œ 데이터 전솑 μ‹€νŒ¨: {resp.status}, {chunk_number} 번째 μ‹œλ„")
186
  except aiohttp.ClientError as e:
187
- logging.error(f"μ›Ήν›… 전솑 쀑 였λ₯˜ λ°œμƒ: {e}, {chunk_number} 번째 μ‹œλ„")
188
- await asyncio.sleep(1) # μž¬μ‹œλ„ 전에 μž μ‹œ λŒ€κΈ°
 
189
 
 
 
 
190
  return False # μž¬μ‹œλ„ 횟수 초과 μ‹œ μ‹€νŒ¨λ‘œ κ°„μ£Ό
191
 
 
 
192
  async def create_thread_and_send_replies(message, video_id, comments, replies, session):
193
  thread = await message.channel.create_thread(name=f"{message.author.name}의 λŒ“κΈ€ λ‹΅κΈ€", message=message)
194
  webhook_data = {"video_id": video_id, "replies": []}
 
174
  logging.debug(f'μƒμ„±λœ λ‹΅κΈ€: {replies}')
175
  return replies
176
 
177
+
178
+
179
  async def send_webhook_data(session, chunk_data, chunk_number):
180
+ max_retries = 3 # μ΅œλŒ€ μž¬μ‹œλ„ 횟수
181
+ retry_delay = 1 # μž¬μ‹œλ„ μ‚¬μ΄μ˜ λŒ€κΈ° μ‹œκ°„ (초)
182
+
183
+ for attempt in range(max_retries):
184
  try:
185
+ async with session.post(WEBHOOK_URL, json=chunk_data) as response:
186
+ if response.status == 200:
187
+ logging.info(f"μ›Ήν›…μœΌλ‘œ 데이터 전솑 성곡: 청크 {chunk_number}, μ‹œλ„ {attempt+1}")
188
  return True # 성곡 μ‹œ μ’…λ£Œ
189
  else:
190
+ logging.error(f"μ›Ήν›…μœΌλ‘œ 데이터 전솑 μ‹€νŒ¨: HTTP {response.status}, 청크 {chunk_number}, μ‹œλ„ {attempt+1}")
191
  except aiohttp.ClientError as e:
192
+ logging.error(f"μ›Ήν›… 전솑 쀑 HTTP 였λ₯˜ λ°œμƒ: {e}, 청크 {chunk_number}, μ‹œλ„ {attempt+1}")
193
+ except Exception as e:
194
+ logging.error(f"μ›Ήν›… 전솑 쀑 μ•Œ 수 μ—†λŠ” 였λ₯˜ λ°œμƒ: {e}, 청크 {chunk_number}, μ‹œλ„ {attempt+1}")
195
 
196
+ await asyncio.sleep(retry_delay) # μž¬μ‹œλ„ 전에 1초 λŒ€κΈ°
197
+
198
+ logging.error(f"μ›Ήν›… 데이터 전솑 μ‹€νŒ¨, λͺ¨λ“  μž¬μ‹œλ„ μ†Œμ§„: 청크 {chunk_number}")
199
  return False # μž¬μ‹œλ„ 횟수 초과 μ‹œ μ‹€νŒ¨λ‘œ κ°„μ£Ό
200
 
201
+
202
+
203
  async def create_thread_and_send_replies(message, video_id, comments, replies, session):
204
  thread = await message.channel.create_thread(name=f"{message.author.name}의 λŒ“κΈ€ λ‹΅κΈ€", message=message)
205
  webhook_data = {"video_id": video_id, "replies": []}