From b3e11edfa8f26765469a367382f478e7aa6b5592 Mon Sep 17 00:00:00 2001 From: Nicolas Le Manchet Date: Wed, 16 Oct 2019 10:43:30 +0200 Subject: [PATCH] Fix Python 3 compatibility with RQ --- redash/__init__.py | 1 + redash/cli/rq.py | 8 +++++--- redash/schedule.py | 4 ++-- redash/settings/__init__.py | 2 ++ redash/tasks/queries/maintenance.py | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/redash/__init__.py b/redash/__init__.py index d7b3c5eed3..87ac101c34 100644 --- a/redash/__init__.py +++ b/redash/__init__.py @@ -39,6 +39,7 @@ def setup_logging(): setup_logging() redis_connection = redis.from_url(settings.REDIS_URL) +rq_redis_connection = redis.from_url(settings.RQ_REDIS_URL) mail = Mail() migrate = Migrate() statsd_client = StatsClient(host=settings.STATSD_HOST, port=settings.STATSD_PORT, prefix=settings.STATSD_PREFIX) diff --git a/redash/cli/rq.py b/redash/cli/rq.py index 76e5544f2d..9f6fcc5a0d 100644 --- a/redash/cli/rq.py +++ b/redash/cli/rq.py @@ -7,7 +7,7 @@ from flask.cli import AppGroup from rq import Connection, Worker -from redash import redis_connection +from redash import rq_redis_connection from redash.schedule import rq_scheduler, schedule_periodic_jobs manager = AppGroup(help="RQ management commands.") @@ -22,7 +22,9 @@ def scheduler(): @manager.command() @argument('queues', nargs=-1) def worker(queues='default'): - with Connection(redis_connection): + if not queues: + queues = ('default', ) + with Connection(rq_redis_connection): w = Worker(queues) w.work() @@ -30,7 +32,7 @@ def worker(queues='default'): @manager.command() def healthcheck(): hostname = socket.gethostname() - with Connection(redis_connection): + with Connection(rq_redis_connection): all_workers = Worker.all() local_workers = [w for w in all_workers if w.hostname == hostname] diff --git a/redash/schedule.py b/redash/schedule.py index 43610a955b..a48f557337 100644 --- a/redash/schedule.py +++ b/redash/schedule.py @@ -5,13 +5,13 @@ from rq_scheduler import Scheduler -from redash import settings, redis_connection +from redash import settings, rq_redis_connection from redash.tasks import (sync_user_details, refresh_queries, empty_schedules, refresh_schemas, cleanup_query_results, version_check, send_aggregated_errors) -rq_scheduler = Scheduler(connection=redis_connection, +rq_scheduler = Scheduler(connection=rq_redis_connection, queue_name="periodic", interval=5) diff --git a/redash/settings/__init__.py b/redash/settings/__init__.py index 61017446df..a5de3b64f6 100644 --- a/redash/settings/__init__.py +++ b/redash/settings/__init__.py @@ -26,6 +26,8 @@ SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_ECHO = False +RQ_REDIS_URL = os.environ.get("RQ_REDIS_URL", _REDIS_URL) + # Celery related settings CELERY_BROKER = os.environ.get("REDASH_CELERY_BROKER", _REDIS_URL) CELERY_RESULT_BACKEND = os.environ.get( diff --git a/redash/tasks/queries/maintenance.py b/redash/tasks/queries/maintenance.py index ea78667565..40d3155ed7 100644 --- a/redash/tasks/queries/maintenance.py +++ b/redash/tasks/queries/maintenance.py @@ -50,7 +50,7 @@ def refresh_queries(): try: query_text = query.parameterized.apply(parameters).query except InvalidParameterError as e: - error = u"Skipping refresh of {} because of invalid parameters: {}".format(query.id, e.message) + error = u"Skipping refresh of {} because of invalid parameters: {}".format(query.id, str(e)) track_failure(query, error) continue except QueryDetachedFromDataSourceError as e: