Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion loq.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ max_lines = 750
# Source files that still need exceptions above 750
[[rules]]
path = "python/src/docket/worker.py"
max_lines = 1479
max_lines = 1482

[[rules]]
path = "python/src/docket/cli/__init__.py"
Expand Down
7 changes: 5 additions & 2 deletions python/src/docket/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,11 @@ async def process_completed_tasks() -> None:
await process_completed_tasks()
available_slots = self.concurrency - len(active_tasks)
if available_slots <= 0:
await asyncio.sleep(
self.minimum_check_interval.total_seconds()
# Wake as soon as a task frees a slot.
await asyncio.wait(
active_tasks,
timeout=self.minimum_check_interval.total_seconds(),
return_when=asyncio.FIRST_COMPLETED,
)
continue
sources = [get_new_deliveries]
Expand Down
5 changes: 4 additions & 1 deletion python/tests/concurrency_limits/test_waiter_safeguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ async def the_task(
finished.append(name)

async def is_woken(task_key: str) -> bool:
# A parked waiter's state is "scheduled", and the wake sets "queued".
# The worker can claim and finish the woken task before this probe
# runs, so any state past "scheduled" means the wake happened.
async with docket.redis() as redis:
state = await redis.hget(docket.runs_key(task_key), "state")
return state == b"queued"
return state is not None and state != b"scheduled"

add = docket.add

Expand Down