Skip to content

Commit

Permalink
Add task_name to metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
debonzi authored and debonzi-geru committed Nov 5, 2019
1 parent ce9164d commit 9d0211b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion crossover/__init__.py
Expand Up @@ -124,7 +124,7 @@ def __init__(self, broker, remote_task_name, task=CROSSOVER_ROUTER_NAME, queue=C
self.remote_task_name = remote_task_name

def __call__(self, *args, **kwargs):
metrics = CrossoverMetrics()
metrics = CrossoverMetrics(task_name=self.remote_task_name)
metrics.set_origin_time()

kwargs['task_name'] = self.remote_task_name
Expand All @@ -139,9 +139,11 @@ def __call__(self, *args, **kwargs):
class CrossoverMetrics(object):
def __init__(
self,
task_name=None,
origin_time=None,
remote_time=None,
):
self.task_name = task_name
self.origin_time = origin_time
self.remote_time = remote_time

Expand All @@ -163,12 +165,14 @@ def load(cls, xover_payload):
if not metrics:
return None
return cls(
task_name=metrics.get('_task_name'),
origin_time=metrics.get('_origin_time'),
remote_time=metrics.get('_remote_time')
)

def dump(self):
return dict(
_task_name=self.task_name,
_origin_time=self.origin_time,
_remote_time=self.remote_time,
)
Expand Down
1 change: 1 addition & 0 deletions examples/project_1/project.py
Expand Up @@ -44,3 +44,4 @@ def calculate_times(callback_meta, x, y):
@crossover.metrics_subscribe()
def metrics_subscriber(metrics):
redis.db.set('dispatch_queue_time', metrics.dispatch_queue_time)
redis.db.set('task_name', metrics.task_name)
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -38,7 +38,7 @@ def long_desc_img_replacer(long_desc):


setup(name='celery-crossover',
version='1.1.11',
version='1.1.12',
description='Celery Crossover aims to make it really easy to execute tasks in another service.',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
2 changes: 2 additions & 0 deletions tests/test_crossover.py
Expand Up @@ -27,6 +27,7 @@ def test_auto_callback(worker_1, worker_2, p1_client, redis):
dispatch_queue_time = redis.get('dispatch_queue_time')
assert dispatch_queue_time is not None
assert isinstance(float(dispatch_queue_time), float)
assert redis.get('task_name') == b'plus'


def test_callback_meta(worker_1, worker_2, p1_client, redis):
Expand All @@ -53,3 +54,4 @@ def test_callback_meta(worker_1, worker_2, p1_client, redis):
dispatch_queue_time = redis.get('dispatch_queue_time')
assert dispatch_queue_time is not None
assert isinstance(float(dispatch_queue_time), float)
assert redis.get('task_name') == b'times'

0 comments on commit 9d0211b

Please sign in to comment.