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
1 change: 1 addition & 0 deletions CHANGES/plugin_api/+remove-sync-immediate-suport.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed support for synchronous immediate tasks.
18 changes: 5 additions & 13 deletions pulpcore/tasking/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import traceback
import tempfile
import threading
from asgiref.sync import sync_to_async
from gettext import gettext as _

from django.conf import settings
Expand All @@ -21,7 +20,6 @@
current_task,
get_domain,
get_prn,
deprecation_logger,
)
from pulpcore.constants import (
TASK_FINAL_STATES,
Expand Down Expand Up @@ -86,19 +84,11 @@ def _execute_task(task):
immediate = task.immediate
is_coroutine_fn = asyncio.iscoroutinefunction(func)

if not is_coroutine_fn:
if immediate:
deprecation_logger.warning(
"Immediate tasks must be coroutine functions. "
"Support for non-coroutine immediate tasks will be dropped "
"in pulpcore 3.85."
)
func = sync_to_async(func)
is_coroutine_fn = True
else:
func(*args, **kwargs)
if immediate and not is_coroutine_fn:
raise ValueError("Immediate tasks must be async functions.")

if is_coroutine_fn:
# both regular and immediate tasks can be coroutines, but only immediate must timeout
_logger.debug("Task is coroutine %s", task.pk)
coro = func(*args, **kwargs)
if immediate:
Expand All @@ -115,6 +105,8 @@ def _execute_task(task):
timeout=IMMEDIATE_TIMEOUT,
)
)
else:
func(*args, **kwargs)

except Exception:
exc_type, exc, tb = sys.exc_info()
Expand Down
21 changes: 10 additions & 11 deletions pulpcore/tests/functional/api/test_tasking.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,22 +490,21 @@ def test_succeeds_on_api_worker(self, pulpcore_bindings, dispatch_task):
assert task.worker is None

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

@pytest.mark.parallel
def test_timeouts_on_api_worker(self, pulpcore_bindings, dispatch_task):
Expand Down