From c4ebfc66b910a60b2f4ccdbd025ca21e90f347cb Mon Sep 17 00:00:00 2001 From: Stan Triepels <1939656+GDay@users.noreply.github.com> Date: Sat, 17 Sep 2022 01:48:07 +0200 Subject: [PATCH] Show function name in log when running task (#3) * refactor: show function name as it runs * feat: log func name when processed Co-authored-by: Noortheen Raja --- django_q/cluster.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/django_q/cluster.py b/django_q/cluster.py index 9bce4f5..a1b76d2 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")) @@ -408,8 +409,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 +420,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 +453,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):