Skip to content

Commit 9e6ec3c

Browse files
committed
Remove support for non-async immediate tasks
1 parent f5d03dd commit 9e6ec3c

3 files changed

Lines changed: 16 additions & 24 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Removed support for synchronous immediate tasks.

pulpcore/tasking/tasks.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import traceback
99
import tempfile
1010
import threading
11-
from asgiref.sync import sync_to_async
1211
from gettext import gettext as _
1312

1413
from django.conf import settings
@@ -21,7 +20,6 @@
2120
current_task,
2221
get_domain,
2322
get_prn,
24-
deprecation_logger,
2523
)
2624
from pulpcore.constants import (
2725
TASK_FINAL_STATES,
@@ -86,19 +84,11 @@ def _execute_task(task):
8684
immediate = task.immediate
8785
is_coroutine_fn = asyncio.iscoroutinefunction(func)
8886

89-
if not is_coroutine_fn:
90-
if immediate:
91-
deprecation_logger.warning(
92-
"Immediate tasks must be coroutine functions. "
93-
"Support for non-coroutine immediate tasks will be dropped "
94-
"in pulpcore 3.85."
95-
)
96-
func = sync_to_async(func)
97-
is_coroutine_fn = True
98-
else:
99-
func(*args, **kwargs)
87+
if immediate and not is_coroutine_fn:
88+
raise ValueError("Immediate tasks must be async functions.")
10089

10190
if is_coroutine_fn:
91+
# both regular and immediate tasks can be coroutines, but only immediate must timeout
10292
_logger.debug("Task is coroutine %s", task.pk)
10393
coro = func(*args, **kwargs)
10494
if immediate:
@@ -115,6 +105,8 @@ def _execute_task(task):
115105
timeout=IMMEDIATE_TIMEOUT,
116106
)
117107
)
108+
else:
109+
func(*args, **kwargs)
118110

119111
except Exception:
120112
exc_type, exc, tb = sys.exc_info()

pulpcore/tests/functional/api/test_tasking.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -490,22 +490,21 @@ def test_succeeds_on_api_worker(self, pulpcore_bindings, dispatch_task):
490490
assert task.worker is None
491491

492492
@pytest.mark.parallel
493-
def test_executes_on_api_worker_when_no_async(self, pulpcore_bindings, dispatch_task, capsys):
493+
def test_executes_on_api_worker_when_no_async(
494+
self, pulpcore_bindings, dispatch_task, monitor_task
495+
):
494496
"""
495497
GIVEN a task with no resource requirements
496498
AND the task IS NOT an async function
497499
WHEN dispatching a task as immediate
498-
THEN the task completes with no associated worker
500+
THEN the dispatch should throw an error
499501
"""
500-
# TODO: on 3.85 this should throw an error
501-
task_href = dispatch_task(
502-
"pulpcore.app.tasks.test.sleep", args=(LT_TIMEOUT,), immediate=True
503-
)
504-
stderr_content = capsys.readouterr().err
505-
task = pulpcore_bindings.TasksApi.read(task_href)
506-
assert task.state == "completed"
507-
assert task.worker is None
508-
assert "Support for non-coroutine immediate tasks will be dropped" in stderr_content
502+
with pytest.raises(PulpTaskError) as ctx:
503+
task_href = dispatch_task(
504+
"pulpcore.app.tasks.test.sleep", args=(LT_TIMEOUT,), immediate=True
505+
)
506+
monitor_task(task_href)
507+
assert "Immediate tasks must be async functions" in ctx.value.task.error["description"]
509508

510509
@pytest.mark.parallel
511510
def test_timeouts_on_api_worker(self, pulpcore_bindings, dispatch_task):

0 commit comments

Comments
 (0)