|
| 1 | +From 15d6f725a1304d0850c1569e75ad5c9f41024a96 Mon Sep 17 00:00:00 2001 |
| 2 | +From: =?UTF-8?q?Andr=C3=A9=20=22decko=22=20de=20Brito?= < [email protected]> |
| 3 | +Date: Tue, 15 Apr 2025 11:16:12 -0300 |
| 4 | +Subject: [PATCH] Add the task name to the task log. |
| 5 | + |
| 6 | +Close #6482 |
| 7 | +--- |
| 8 | + CHANGES/6482.feature | 1 + |
| 9 | + pulpcore/tasking/tasks.py | 19 +++++++++++++------ |
| 10 | + pulpcore/tasking/worker.py | 4 ++-- |
| 11 | + 3 files changed, 16 insertions(+), 8 deletions(-) |
| 12 | + create mode 100644 CHANGES/6482.feature |
| 13 | + |
| 14 | +diff --git a/CHANGES/6482.feature b/CHANGES/6482.feature |
| 15 | +new file mode 100644 |
| 16 | +index 000000000..a700a8761 |
| 17 | +--- /dev/null |
| 18 | ++++ b/CHANGES/6482.feature |
| 19 | +@@ -0,0 +1 @@ |
| 20 | ++Added the `task_name` and if it's a `task.immediate` to the `Starting task ...` log entry. |
| 21 | +diff --git a/pulpcore/tasking/tasks.py b/pulpcore/tasking/tasks.py |
| 22 | +index 5018f96ca..16616214b 100644 |
| 23 | +--- a/pulpcore/tasking/tasks.py |
| 24 | ++++ b/pulpcore/tasking/tasks.py |
| 25 | +@@ -60,7 +60,14 @@ def _execute_task(task): |
| 26 | + task.set_running() |
| 27 | + domain = get_domain() |
| 28 | + try: |
| 29 | +- _logger.info(_("Starting task %s in domain: %s"), task.pk, domain.name) |
| 30 | ++ _logger.info( |
| 31 | ++ "Starting task id: %s in domain: %s, task_type: %s, immediate: %s, deferred: %s", |
| 32 | ++ task.pk, |
| 33 | ++ domain.name, |
| 34 | ++ task.name, |
| 35 | ++ str(task.immediate), |
| 36 | ++ str(task.deferred), |
| 37 | ++ ) |
| 38 | + |
| 39 | + # Execute task |
| 40 | + module_name, function_name = task.name.rsplit(".", 1) |
| 41 | +@@ -70,7 +77,7 @@ def _execute_task(task): |
| 42 | + kwargs = task.enc_kwargs or {} |
| 43 | + result = func(*args, **kwargs) |
| 44 | + if asyncio.iscoroutine(result): |
| 45 | +- _logger.debug(_("Task is coroutine %s"), task.pk) |
| 46 | ++ _logger.debug("Task is coroutine %s", task.pk) |
| 47 | + loop = asyncio.get_event_loop() |
| 48 | + loop.run_until_complete(result) |
| 49 | + |
| 50 | +@@ -78,7 +85,7 @@ def _execute_task(task): |
| 51 | + exc_type, exc, tb = sys.exc_info() |
| 52 | + task.set_failed(exc, tb) |
| 53 | + _logger.info( |
| 54 | +- _("Task[{task_type}] {task_pk} failed ({exc_type}: {exc}) in domain: {domain}").format( |
| 55 | ++ "Task[{task_type}] {task_pk} failed ({exc_type}: {exc}) in domain: {domain}".format( |
| 56 | + task_type=task.name, |
| 57 | + task_pk=task.pk, |
| 58 | + exc_type=exc_type.__name__, |
| 59 | +@@ -90,7 +97,7 @@ def _execute_task(task): |
| 60 | + send_task_notification(task) |
| 61 | + else: |
| 62 | + task.set_completed() |
| 63 | +- _logger.info(_("Task completed %s in domain: %s"), task.pk, domain.name) |
| 64 | ++ _logger.info("Task completed %s in domain: %s", task.pk, domain.name) |
| 65 | + send_task_notification(task) |
| 66 | + |
| 67 | + |
| 68 | +@@ -170,7 +177,7 @@ def dispatch( |
| 69 | + with contextlib.ExitStack() as stack: |
| 70 | + with transaction.atomic(): |
| 71 | + # Task creation need to be serialized so that pulp_created will provide a stable order |
| 72 | +- # at every time. We specifically need to ensure that each task, when commited to the |
| 73 | ++ # at every time. We specifically need to ensure that each task, when committed to the |
| 74 | + # task table will be the newest with respect to `pulp_created`. |
| 75 | + with connection.cursor() as cursor: |
| 76 | + # Wait for exclusive access and release automatically after transaction. |
| 77 | +@@ -275,7 +282,7 @@ def cancel_task(task_id): |
| 78 | + ) |
| 79 | + return task |
| 80 | + _logger.info( |
| 81 | +- _("Canceling task: {id} in domain: {name}").format(id=task_id, name=task.pulp_domain.name) |
| 82 | ++ "Canceling task: {id} in domain: {name}".format(id=task_id, name=task.pulp_domain.name) |
| 83 | + ) |
| 84 | + |
| 85 | + # This is the only valid transition without holding the task lock |
| 86 | +diff --git a/pulpcore/tasking/worker.py b/pulpcore/tasking/worker.py |
| 87 | +index 185b6802a..6a938f9c8 100644 |
| 88 | +--- a/pulpcore/tasking/worker.py |
| 89 | ++++ b/pulpcore/tasking/worker.py |
| 90 | +@@ -69,7 +69,7 @@ class PulpcoreWorker: |
| 91 | + self.versions = {app.label: app.version for app in pulp_plugin_configs()} |
| 92 | + self.cursor = connection.cursor() |
| 93 | + self.worker = self.handle_worker_heartbeat() |
| 94 | +- # This defaults to immediate task cancelation. |
| 95 | ++ # This defaults to immediate task cancellation. |
| 96 | + # It will be set into the future on moderately graceful worker shutdown, |
| 97 | + # and set to None for fully graceful shutdown. |
| 98 | + self.task_grace_timeout = timezone.now() |
| 99 | +@@ -401,7 +401,7 @@ class PulpcoreWorker: |
| 100 | + seconds=TASK_KILL_INTERVAL |
| 101 | + ) |
| 102 | + _logger.info( |
| 103 | +- "Aborting current task %s in domain: %s due to cancelation.", |
| 104 | ++ "Aborting current task %s in domain: %s due to cancellation.", |
| 105 | + task.pk, |
| 106 | + domain.name, |
| 107 | + ) |
| 108 | +-- |
| 109 | +2.49.0 |
| 110 | + |
0 commit comments