Skip to content

Commit

Permalink
Metrics working.
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 011b8d7 commit ce9164d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ htmlcov/
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/

# Translations
Expand Down
10 changes: 6 additions & 4 deletions crossover/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ class CrossoverRouter(celery.Task):
name = CROSSOVER_ROUTER_NAME

def run(self, *args, **kwargs):
metrics = CrossoverMetrics.load(kwargs)
metrics.set_remote_time()

app = celery.current_app if celery.VERSION < self.CELERY_4_VERSION else self.app
task_name = kwargs.pop('task_name')

metrics = CrossoverMetrics.load(kwargs)
metrics.set_remote_time()
metrics_subscribe.call_subscribers(metrics)

logger.debug('Got Crossover task: {}'.format(task_name))
Expand Down Expand Up @@ -123,12 +124,13 @@ 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.set_origin_time()

kwargs['task_name'] = self.remote_task_name
if 'callback' in kwargs:
kwargs['callback'] = _build_callback(kwargs['callback'])

metrics = CrossoverMetrics()
metrics.set_origin_time()
kwargs['metrics'] = metrics.dump()

requests.post(self.url, json=kwargs)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def long_desc_img_replacer(long_desc):

requires = [
'celery[redis]>=3.1.20',
'requests-celery-adapters>=2.0.13',
'requests-celery-adapters>=2.0.14',
'six>=1.11.0'
]

Expand Down
8 changes: 7 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

from examples.database import redis as redis_


class ProjectWorker(object):
CMD_LINE = ''

def start(self):
self.sp = subprocess.Popen(self.CMD_LINE)

def stop(self):
self.sp.terminate()
self.sp.send_signal(signal.SIGINT)
self.sp.wait()


class Project1Worker(ProjectWorker):
Expand All @@ -22,6 +24,10 @@ class Project2Worker(ProjectWorker):
CMD_LINE = 'celery worker -A examples.project_2.project.app -l INFO'.split(' ')


def pytest_configure():
redis_.db.flushall()


@pytest.fixture(scope='session')
def worker_1():
pw = Project1Worker()
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ envlist =

[testenv]
deps =
pytest
pytest==4.6.6
celery3120: celery[redis]==3.1.20
celery3120: kombu==3.0.37
celery3120: redis==2.10.6
Expand Down

0 comments on commit ce9164d

Please sign in to comment.