88from virtuals_acp import ACPJob , ACPJobPhase
99from game_sdk .game .custom_types import Argument , Function , FunctionResultStatus
1010from game_sdk .game .agent import Agent
11+ from collections import deque
1112from rich import print , box
1213from rich .panel import Panel
1314from dotenv import load_dotenv
@@ -55,7 +56,7 @@ def seller(use_thread_lock: bool = True):
5556 return
5657
5758 # Thread-safe job queue setup
58- job_queue = []
59+ job_queue = deque ()
5960 job_queue_lock = threading .Lock ()
6061 job_event = threading .Event ()
6162
@@ -78,14 +79,14 @@ def safe_pop_job():
7879 with job_queue_lock :
7980 print ("[pop] Lock acquired." )
8081 if job_queue :
81- job = job_queue .pop ( 0 )
82+ job = job_queue .popleft ( )
8283 print (f"[pop] Job popped: { job .id } " )
8384 return job
8485 else :
8586 print ("[pop] Queue is empty." )
8687 else :
8788 if job_queue :
88- job = job_queue .pop ( 0 )
89+ job = job_queue .popleft ( )
8990 print (f"[pop] Job popped (no lock): { job .id } " )
9091 return job
9192 else :
@@ -94,19 +95,28 @@ def safe_pop_job():
9495
9596 # Background thread worker: process jobs one by one
9697 def job_worker ():
97- print ("[worker] Job worker started, waiting for jobs." )
9898 while True :
9999 job_event .wait ()
100- print ("[worker] job_event triggered." )
101100
102- job = safe_pop_job ()
103- while job :
104- print (f"[worker] Processing job { job .id } " )
105- process_job (job )
101+ # Process all available jobs
102+ while True :
106103 job = safe_pop_job ()
107-
108- job_event .clear ()
109- print ("[worker] All jobs processed. Waiting again." )
104+ if not job :
105+ break
106+ try :
107+ process_job (job )
108+ except Exception as e :
109+ print (f"❌ Error processing job: { e } " )
110+ # Continue processing other jobs even if one fails
111+
112+ # Clear event only after ensuring no jobs remain
113+ if use_thread_lock :
114+ with job_queue_lock :
115+ if not job_queue :
116+ job_event .clear ()
117+ else :
118+ if not job_queue :
119+ job_event .clear ()
110120
111121 # Event-triggered job task receiver
112122 def on_new_task (job : ACPJob ):
0 commit comments