mayafree commited on
Commit
1c98e2e
ยท
verified ยท
1 Parent(s): cb4a4eb

Update battle_arena.py

Browse files
Files changed (1) hide show
  1. battle_arena.py +27 -10
battle_arena.py CHANGED
@@ -10,8 +10,12 @@ from typing import Dict, List, Tuple, Optional
10
 
11
 
12
  async def init_battle_arena_db(db_path: str):
13
- """๋ฐฐํ‹€ ์•„๋ ˆ๋‚˜ ํ…Œ์ด๋ธ” ์ดˆ๊ธฐํ™”"""
14
- async with aiosqlite.connect(db_path) as db:
 
 
 
 
15
  # ๋ฐฐํ‹€ ๋ฐฉ ํ…Œ์ด๋ธ”
16
  await db.execute("""
17
  CREATE TABLE IF NOT EXISTS battle_rooms (
@@ -90,7 +94,9 @@ async def create_battle_room(
90
  if is_npc and battle_type != 'opinion':
91
  return False, "โŒ NPC๋Š” ๋‹ค์ˆ˜๊ฒฐ ์ฃผ์ œ๋งŒ ๊ฐ€๋Šฅ", None
92
 
93
- async with aiosqlite.connect(db_path) as db:
 
 
94
  # GPU ์ฐจ๊ฐ
95
  if is_npc:
96
  cursor = await db.execute(
@@ -165,7 +171,8 @@ async def place_bet(
165
  if bet_amount < 1 or bet_amount > 100:
166
  return False, "โŒ ๋ฒ ํŒ… 1~100 GPU"
167
 
168
- async with aiosqlite.connect(db_path) as db:
 
169
  db.row_factory = aiosqlite.Row
170
 
171
  # ๋ฐฉ ํ™•์ธ
@@ -249,7 +256,8 @@ async def place_bet(
249
 
250
  async def resolve_battle(db_path: str, room_id: int) -> Tuple[bool, str]:
251
  """๋ฐฐํ‹€ ํŒ์ • (50.01% ์ด์ƒ ๋“ํ‘œํ•œ ์ชฝ ์Šน๋ฆฌ)"""
252
- async with aiosqlite.connect(db_path) as db:
 
253
  db.row_factory = aiosqlite.Row
254
 
255
  cursor = await db.execute(
@@ -366,7 +374,8 @@ async def resolve_battle(db_path: str, room_id: int) -> Tuple[bool, str]:
366
 
367
  async def get_active_battles(db_path: str, limit: int = 20) -> List[Dict]:
368
  """์ง„ํ–‰ ์ค‘์ธ ๋ฐฐํ‹€ ๋ชฉ๋ก"""
369
- async with aiosqlite.connect(db_path) as db:
 
370
  db.row_factory = aiosqlite.Row
371
 
372
  cursor = await db.execute(
@@ -419,7 +428,9 @@ async def get_active_battles(db_path: str, limit: int = 20) -> List[Dict]:
419
 
420
  async def auto_resolve_expired_battles(db_path: str):
421
  """๋งŒ๋ฃŒ๋œ ๋ฐฐํ‹€ ์ž๋™ ํŒ์ •"""
422
- async with aiosqlite.connect(db_path) as db:
 
 
423
  cursor = await db.execute(
424
  """SELECT id FROM battle_rooms
425
  WHERE status='active' AND end_time <= ?""",
@@ -516,7 +527,9 @@ async def npc_create_battle(db_path: str) -> Tuple[bool, str]:
516
  num_battles = random.randint(1, 2) # 1-2๊ฐœ ๋žœ๋ค ์ƒ์„ฑ
517
 
518
  # ๐Ÿ”’ ํ˜„์žฌ ํ™œ์„ฑํ™”๋œ ๋ฐฐํ‹€๋ฐฉ ์ œ๋ชฉ ์กฐํšŒ (์ค‘๋ณต ๋ฐฉ์ง€)
519
- async with aiosqlite.connect(db_path) as db:
 
 
520
  cursor = await db.execute("""
521
  SELECT title FROM battle_rooms
522
  WHERE status='active'
@@ -524,7 +537,9 @@ async def npc_create_battle(db_path: str) -> Tuple[bool, str]:
524
  active_titles = {row[0] for row in await cursor.fetchall()}
525
 
526
  for _ in range(num_battles):
527
- async with aiosqlite.connect(db_path) as db:
 
 
528
  # ํ™œ์„ฑ NPC ์ค‘ GPU 50 ์ด์ƒ์ธ NPC ์„ ํƒ
529
  cursor = await db.execute("""
530
  SELECT agent_id, ai_identity, gpu_dollars
@@ -602,7 +617,9 @@ async def npc_auto_bet(db_path: str) -> int:
602
  """
603
  total_bet_count = 0
604
 
605
- async with aiosqlite.connect(db_path) as db:
 
 
606
  # ์ง„ํ–‰์ค‘์ธ ๋ฐฐํ‹€ ๊ฐ€์ ธ์˜ค๊ธฐ
607
  cursor = await db.execute("""
608
  SELECT id, title, option_a, option_b, battle_type
 
10
 
11
 
12
  async def init_battle_arena_db(db_path: str):
13
+ """๋ฐฐํ‹€ ์•„๋ ˆ๋‚˜ ํ…Œ์ด๋ธ” ์ดˆ๊ธฐํ™” (DB ๋ฝ ๋ฐฉ์ง€)"""
14
+ async with aiosqlite.connect(db_path, timeout=30.0) as db:
15
+ # ๐Ÿ”ง WAL ๋ชจ๋“œ ํ™œ์„ฑํ™” (๋™์‹œ ์ ‘๊ทผ ์ตœ์ ํ™”)
16
+ await db.execute("PRAGMA journal_mode=WAL")
17
+ await db.execute("PRAGMA busy_timeout=30000") # 30์ดˆ ๋Œ€๊ธฐ
18
+
19
  # ๋ฐฐํ‹€ ๋ฐฉ ํ…Œ์ด๋ธ”
20
  await db.execute("""
21
  CREATE TABLE IF NOT EXISTS battle_rooms (
 
94
  if is_npc and battle_type != 'opinion':
95
  return False, "โŒ NPC๋Š” ๋‹ค์ˆ˜๊ฒฐ ์ฃผ์ œ๋งŒ ๊ฐ€๋Šฅ", None
96
 
97
+ async with aiosqlite.connect(db_path, timeout=30.0) as db:
98
+ await db.execute("PRAGMA busy_timeout=30000")
99
+
100
  # GPU ์ฐจ๊ฐ
101
  if is_npc:
102
  cursor = await db.execute(
 
171
  if bet_amount < 1 or bet_amount > 100:
172
  return False, "โŒ ๋ฒ ํŒ… 1~100 GPU"
173
 
174
+ async with aiosqlite.connect(db_path, timeout=30.0) as db:
175
+ await db.execute("PRAGMA busy_timeout=30000")
176
  db.row_factory = aiosqlite.Row
177
 
178
  # ๋ฐฉ ํ™•์ธ
 
256
 
257
  async def resolve_battle(db_path: str, room_id: int) -> Tuple[bool, str]:
258
  """๋ฐฐํ‹€ ํŒ์ • (50.01% ์ด์ƒ ๋“ํ‘œํ•œ ์ชฝ ์Šน๋ฆฌ)"""
259
+ async with aiosqlite.connect(db_path, timeout=30.0) as db:
260
+ await db.execute("PRAGMA busy_timeout=30000")
261
  db.row_factory = aiosqlite.Row
262
 
263
  cursor = await db.execute(
 
374
 
375
  async def get_active_battles(db_path: str, limit: int = 20) -> List[Dict]:
376
  """์ง„ํ–‰ ์ค‘์ธ ๋ฐฐํ‹€ ๋ชฉ๋ก"""
377
+ async with aiosqlite.connect(db_path, timeout=30.0) as db:
378
+ await db.execute("PRAGMA busy_timeout=30000")
379
  db.row_factory = aiosqlite.Row
380
 
381
  cursor = await db.execute(
 
428
 
429
  async def auto_resolve_expired_battles(db_path: str):
430
  """๋งŒ๋ฃŒ๋œ ๋ฐฐํ‹€ ์ž๋™ ํŒ์ •"""
431
+ async with aiosqlite.connect(db_path, timeout=30.0) as db:
432
+ await db.execute("PRAGMA busy_timeout=30000")
433
+
434
  cursor = await db.execute(
435
  """SELECT id FROM battle_rooms
436
  WHERE status='active' AND end_time <= ?""",
 
527
  num_battles = random.randint(1, 2) # 1-2๊ฐœ ๋žœ๋ค ์ƒ์„ฑ
528
 
529
  # ๐Ÿ”’ ํ˜„์žฌ ํ™œ์„ฑํ™”๋œ ๋ฐฐํ‹€๋ฐฉ ์ œ๋ชฉ ์กฐํšŒ (์ค‘๋ณต ๋ฐฉ์ง€)
530
+ async with aiosqlite.connect(db_path, timeout=30.0) as db:
531
+ await db.execute("PRAGMA busy_timeout=30000")
532
+
533
  cursor = await db.execute("""
534
  SELECT title FROM battle_rooms
535
  WHERE status='active'
 
537
  active_titles = {row[0] for row in await cursor.fetchall()}
538
 
539
  for _ in range(num_battles):
540
+ async with aiosqlite.connect(db_path, timeout=30.0) as db:
541
+ await db.execute("PRAGMA busy_timeout=30000")
542
+
543
  # ํ™œ์„ฑ NPC ์ค‘ GPU 50 ์ด์ƒ์ธ NPC ์„ ํƒ
544
  cursor = await db.execute("""
545
  SELECT agent_id, ai_identity, gpu_dollars
 
617
  """
618
  total_bet_count = 0
619
 
620
+ async with aiosqlite.connect(db_path, timeout=30.0) as db:
621
+ await db.execute("PRAGMA busy_timeout=30000")
622
+
623
  # ์ง„ํ–‰์ค‘์ธ ๋ฐฐํ‹€ ๊ฐ€์ ธ์˜ค๊ธฐ
624
  cursor = await db.execute("""
625
  SELECT id, title, option_a, option_b, battle_type