Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: show function name as it runs #677

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 9 additions & 6 deletions django_q/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))


Expand All @@ -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
Expand All @@ -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"]):
Expand Down Expand Up @@ -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):
Expand Down