Skip to content

Commit 0ae8327

Browse files
gerrod3pedro-psb
authored andcommitted
Add setting to allow admins to avoid timeout issues with immediate tasks
[PULP-1299] (cherry picked from commit 71c6e2c)
1 parent 5437f41 commit 0ae8327

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added new setting `TASK_PREFER_DEFER` to always defer immediate tasks to a task worker. Useful for systems with slow databases that frequently timeout immediate tasks.

docs/admin/reference/settings.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,16 @@ This time is only accurate to one worker heartbeat corresponding to `WORKER_TTL
392392

393393
Defaults to `600` seconds.
394394

395+
### TASK\_PREFER\_DEFER
396+
397+
For tasks that are designed to run immediately, but could be deferred to a task worker, always choose to defer to the worker.
398+
This is helpful for systems with slow databases that could cause the immediate task to timeout after its 5 second limit.
399+
400+
!!! note
401+
Setting this to `True` will slow your Pulp's task throughput, especially if you perform many immediate tasks frequently.
402+
403+
Defaults to `False`.
404+
395405
### TASK\_PROTECTION\_TIME, TMPFILE\_PROTECTION\_TIME and UPLOAD\_PROTECTION\_TIME
396406

397407
Pulp uses `tasks`, `pulp temporary files` and `uploads` to pass data from the api to worker tasks.

pulpcore/app/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@
391391
# NOTE: "memray" and "pyinstrument" require additional packages to be installed on the system.
392392
TASK_DIAGNOSTICS = [] # ["memory", "pyinstrument", "memray", "logs", "debug-logs"]
393393

394+
# For immediate tasks that can be deferred, always defer them to a worker.
395+
TASK_PREFER_DEFER = False
396+
394397
ANALYTICS = True
395398

396399
HIDE_GUARDED_DISTRIBUTIONS = False

pulpcore/tasking/tasks.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ def dispatch(
289289
Raises:
290290
ValueError: When `resources` is an unsupported type.
291291
"""
292+
if settings.TASK_PREFER_DEFER and deferred and immediate:
293+
immediate = False
292294
# Check WORKER_TYPE setting and delegate to appropriate implementation
293295
if settings.WORKER_TYPE == "redis":
294296
from pulpcore.tasking.redis_tasks import dispatch as redis_dispatch
@@ -347,6 +349,8 @@ async def adispatch(
347349
versions=None,
348350
):
349351
"""Async version of dispatch."""
352+
if settings.TASK_PREFER_DEFER and deferred and immediate:
353+
immediate = False
350354
# Check WORKER_TYPE setting and delegate to appropriate implementation
351355
if settings.WORKER_TYPE == "redis":
352356
from pulpcore.tasking.redis_tasks import adispatch as redis_adispatch

0 commit comments

Comments
 (0)