From 2c395bbb354c66473e1c7e2b160d1316d1d93da7 Mon Sep 17 00:00:00 2001 From: Noortheen Raja Date: Tue, 5 Jul 2022 15:11:13 +0530 Subject: [PATCH 1/2] refactor: show function name as it runs closes #582 --- django_q/cluster.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/django_q/cluster.py b/django_q/cluster.py index 9bce4f5e..25a363fe 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -408,8 +408,8 @@ def worker( :type result_queue: multiprocessing.Queue :type timer: multiprocessing.Value """ - name = current_process().name - logger.info(_(f"{name} ready for work at {current_process().pid}")) + proc_name = current_process().name + logger.info(_(f"{proc_name} ready for work at {current_process().pid}")) task_count = 0 if timeout is None: timeout = -1 @@ -419,7 +419,9 @@ def worker( timer.value = -1 # Idle task_count += 1 # Get the function from the task - logger.info(_(f'{name} processing [{task["name"]}]')) + func = task["func"] + func_name = func.__name__ if hasattr(func, "__name__") else str(func) + logger.info(_(f'{proc_name} processing [{task["name"]}({func_name})]')) f = task["func"] # if it's not an instance try to get it from the string if not callable(task["func"]): @@ -450,7 +452,7 @@ def worker( if task_count == Conf.RECYCLE or rss_check(): timer.value = -2 # Recycled break - logger.info(_(f"{name} stopped doing work")) + logger.info(_(f"{proc_name} stopped doing work")) def save_task(task, broker: Broker): From 445e73d0969dfb3785b2f717823ada2d2ad4f958 Mon Sep 17 00:00:00 2001 From: Noortheen Raja Date: Wed, 13 Jul 2022 14:09:47 +0530 Subject: [PATCH 2/2] feat: log func name when processed --- django_q/cluster.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/django_q/cluster.py b/django_q/cluster.py index 25a363fe..a1b76d2d 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -389,12 +389,13 @@ def monitor(result_queue: Queue, broker: Broker = None): # signal execution done post_execute.send(sender="django_q", task=task) # log the result + info_name = f"{task['name']} ({task['func']})" if task["success"]: # log success - logger.info(_(f"Processed [{task['name']}]")) + logger.info(_(f"Processed [{info_name}]")) else: # log failure - logger.error(_(f"Failed [{task['name']}] - {task['result']}")) + logger.error(_(f"Failed [{info_name}] - {task['result']}")) logger.info(_(f"{name} stopped monitoring results"))