Skip to content

Commit

Permalink
only use concurrency when tasks have tags (#14781)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakekaplan authored Jul 29, 2024
1 parent a364933 commit f0365e6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/prefect/task_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,10 @@ def call_task_fn(
if transaction.is_committed():
result = transaction.read()
else:
if PREFECT_EXPERIMENTAL_ENABLE_CLIENT_SIDE_TASK_ORCHESTRATION.value():
if (
PREFECT_EXPERIMENTAL_ENABLE_CLIENT_SIDE_TASK_ORCHESTRATION.value()
and self.task.tags
):
# Acquire a concurrency slot for each tag, but only if a limit
# matching the tag already exists.
with concurrency(
Expand Down Expand Up @@ -1328,7 +1331,10 @@ async def call_task_fn(
if transaction.is_committed():
result = transaction.read()
else:
if PREFECT_EXPERIMENTAL_ENABLE_CLIENT_SIDE_TASK_ORCHESTRATION.value():
if (
PREFECT_EXPERIMENTAL_ENABLE_CLIENT_SIDE_TASK_ORCHESTRATION.value()
and self.task.tags
):
# Acquire a concurrency slot for each tag, but only if a limit
# matching the tag already exists.
async with aconcurrency(
Expand Down
36 changes: 36 additions & 0 deletions tests/test_task_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,42 @@ def bar():
else:
assert acquire_spy.call_count == 0

async def test_no_tags_no_concurrency(self):
@task
async def bar():
return 42

with mock.patch(
"prefect.concurrency.asyncio._acquire_concurrency_slots",
wraps=_acquire_concurrency_slots,
) as acquire_spy:
with mock.patch(
"prefect.concurrency.asyncio._release_concurrency_slots",
wraps=_release_concurrency_slots,
) as release_spy:
await bar()

assert acquire_spy.call_count == 0
assert release_spy.call_count == 0

def test_no_tags_no_concurrency_sync(self):
@task
def bar():
return 42

with mock.patch(
"prefect.concurrency.sync._acquire_concurrency_slots",
wraps=_acquire_concurrency_slots,
) as acquire_spy:
with mock.patch(
"prefect.concurrency.sync._release_concurrency_slots",
wraps=_release_concurrency_slots,
) as release_spy:
bar()

assert acquire_spy.call_count == 0
assert release_spy.call_count == 0

async def test_tag_concurrency_does_not_create_limits(
self, enable_client_side_task_run_orchestration, prefect_client
):
Expand Down

0 comments on commit f0365e6

Please sign in to comment.