Skip to content

Commit

Permalink
Fix Python 3 compatibility with RQ
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasLM committed Oct 16, 2019
1 parent d2fad33 commit b3e11ed
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions redash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions redash/cli/rq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -22,15 +22,17 @@ 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()


@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]
Expand Down
4 changes: 2 additions & 2 deletions redash/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions redash/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_ECHO = False

RQ_REDIS_URL = os.environ.get("RQ_REDIS_URL", _REDIS_URL)

This comment has been minimized.

Copy link
@rauchy

rauchy Oct 16, 2019

Contributor

@NicolasLM what's the motivation for splitting this?

This comment has been minimized.

Copy link
@arikfr

arikfr Oct 16, 2019

Member

@rauchy see the comment I just made on your branch. This fixes what I was describing there the decode_responses. I guess this is a simpler fix than what I described. 💯

This comment has been minimized.

Copy link
@rauchy

rauchy Oct 16, 2019

Contributor

I just read that, but I'm probably missing something - both redis URLs are constructed the same, no?

This comment has been minimized.

Copy link
@rauchy

rauchy Oct 16, 2019

Contributor

OK, just found d31da96

👍


# Celery related settings
CELERY_BROKER = os.environ.get("REDASH_CELERY_BROKER", _REDIS_URL)
CELERY_RESULT_BACKEND = os.environ.get(
Expand Down
2 changes: 1 addition & 1 deletion redash/tasks/queries/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b3e11ed

Please sign in to comment.