diff --git a/task_queue.py b/task_queue.py index f5003cb..211cb29 100644 --- a/task_queue.py +++ b/task_queue.py @@ -248,6 +248,9 @@ async def wait_for_turn(queue_name: str, command: str | None = None) -> int: except LookupError: pass # Running outside request context (e.g., in tests) + # Compute command preview once for status messages (truncate long commands) + cmd_preview = (command[:50] + "...") if command and len(command) > 50 else command + with get_db() as conn: cursor = conn.execute( "INSERT INTO queue (queue_name, status, pid, server_id, command) VALUES (?, ?, ?, ?, ?)", @@ -264,7 +267,10 @@ async def wait_for_turn(queue_name: str, command: str | None = None) -> int: if ctx: await ctx.info( - log_fmt(f"Request #{task_id} received. Entering '{queue_name}' queue.") + log_fmt( + f"Task #{task_id} queued{f' ({cmd_preview})' if cmd_preview else ''}. " + f"Entering '{queue_name}' queue." + ) ) last_pos = -1 @@ -293,12 +299,12 @@ async def wait_for_turn(queue_name: str, command: str | None = None) -> int: if pos != last_pos: if ctx: - await ctx.info(log_fmt(f"Position #{pos} in queue. Waiting...")) + await ctx.info(log_fmt(f"Task #{task_id} is position #{pos} in queue. Waiting...")) last_pos = pos elif wait_ticks % 10 == 0 and ctx: # Update every ~10 polls await ctx.info( log_fmt( - f"Still waiting... Position #{pos} ({int(wait_ticks * POLL_INTERVAL_WAITING)}s elapsed)" + f"Task #{task_id} still waiting... Position #{pos} ({int(wait_ticks * POLL_INTERVAL_WAITING)}s elapsed)" ) ) @@ -329,7 +335,8 @@ async def wait_for_turn(queue_name: str, command: str | None = None) -> int: wait_time_seconds=round(wait_time, 2), ) if ctx: - await ctx.info(log_fmt("Lock ACQUIRED. Starting execution.")) + msg = f"Task #{task_id} lock ACQUIRED.{f' Running: {cmd_preview}' if cmd_preview else ''}" + await ctx.info(log_fmt(msg)) return task_id await asyncio.sleep(POLL_INTERVAL_READY) @@ -368,7 +375,7 @@ async def release_lock(task_id: int): pass if ctx: - await ctx.info(log_fmt("Task complete. Queue slot released.")) + await ctx.info(log_fmt(f"Task #{task_id} complete. Queue slot released.")) # --- The Tool ---