Skip to content

Commit

Permalink
Move Celery signal callback connections back.
Browse files Browse the repository at this point in the history
  • Loading branch information
jezdez committed Apr 18, 2019
1 parent 5e5ea9e commit a279e7a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 3 additions & 0 deletions redash/metrics/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import socket
import time

from celery.signals import task_postrun, task_prerun
from redash import settings, statsd_client
from redash.utils import json_dumps

tasks_start_time = {}


@task_prerun.connect
def task_prerun_handler(signal, sender, task_id, task, args, kwargs, **kw):
try:
tasks_start_time[task_id] = time.time()
Expand All @@ -25,6 +27,7 @@ def metric_name(name, tags):
return "{},{}".format(name, tags_string)


@task_postrun.connect
def task_postrun_handler(signal, sender, task_id, task, args, kwargs, retval, state, **kw):
try:
run_time = 1000 * (time.time() - tasks_start_time.pop(task_id))
Expand Down
5 changes: 0 additions & 5 deletions redash/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from celery.signals import task_postrun, task_prerun, worker_process_init

from redash import create_app, settings
from redash.metrics.celery import task_postrun_handler, task_prerun_handler


celery = Celery('redash',
Expand Down Expand Up @@ -68,10 +67,6 @@ def __call__(self, *args, **kwargs):

celery.Task = ContextTask

# Connect the task signal handles for Redash metrics
task_prerun.connect(task_prerun_handler)
task_postrun.connect(task_postrun_handler)


# Create Flask app after forking a new worker, to make sure no resources are shared between processes.
@worker_process_init.connect
Expand Down

0 comments on commit a279e7a

Please sign in to comment.