Open JereMalinen opened 5 years ago
I need to monitor tasks with Newrelic, here is some documentation: https://docs.newrelic.com/docs/agents/python-agent/supported-features/python-background-tasks
Documented way seems like I would need to remember to decorate all my tasks separately, which isn't too convenient. So I tried to leverage pre_execute signal https://github.com/Koed00/django-q/blob/master/django_q/cluster.py#L375 but could not effectively change the func from there.
pre_execute
func
Example code:
from django_q.signals import pre_execute class RunTaskWithNewrelic: def __init__(self, f, task_name): self.f = f self.task_name = task_name def __call__(self, *args, **kwargs): print('newrelic task ' * 100) with newrelic.agent.BackgroundTask('qcluster', name=self.task_name): r = self.f(*args, **kwargs) return r def newrelic_execute_callback(sender, func, task, **kwargs): print('newrelic_execute_callback ' * 100) func = RunTaskWithNewrelic(func, task['name']) pre_execute.connect(newrelic_execute_callback)
Are there any smart solutions? =)
Added solution: https://github.com/Koed00/django-q/pull/348
I need to monitor tasks with Newrelic, here is some documentation: https://docs.newrelic.com/docs/agents/python-agent/supported-features/python-background-tasks
Documented way seems like I would need to remember to decorate all my tasks separately, which isn't too convenient. So I tried to leverage
pre_execute
signal https://github.com/Koed00/django-q/blob/master/django_q/cluster.py#L375 but could not effectively change thefunc
from there.Example code:
Are there any smart solutions? =)