Skip to content

Commit

Permalink
Handle the case where the Connection to Redis uses Sentinels
Browse files Browse the repository at this point in the history
Currently, when PyYAML is not installed, `rqstats -y` prints an error
message, but it still exits with a 0 exit code, indicating success. Fix
that, along with a few related issues:

* The error message was printed to stdout rather than stderr.

* The name of the library in the message was incorrect (LibYAML is a C
  library; the Python library is PyYAML).

After this change, you need to install PyYAML to run the testsuite, so
modify the GitHub workflow accordingly. Also, make sure to install all
packages at once, to make sure that later install commands don't overwrite
the result of the earlier ones.
  • Loading branch information
SpecLad authored and malaoui-cf committed Sep 3, 2024
1 parent d33163d commit e3fefdb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion django_rq/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.core.exceptions import ImproperlyConfigured
from django.db import connections
from redis.sentinel import SentinelConnectionPool
from rq.command import send_stop_job_command
from rq.job import Job
from rq.registry import (
Expand Down Expand Up @@ -102,7 +103,11 @@ def get_scheduler_statistics():
# to handle the possibility of a configuration with multiple redis connections and scheduled
# jobs in more than one of them
queue = get_queue_by_index(index)
connection = queue.connection.connection_pool.connection_kwargs
if isinstance(queue.connection.connection_pool, SentinelConnectionPool):
first_sentinel = queue.connection.connection_pool.sentinel_manager.sentinels[0]
connection = first_sentinel.connection_pool.connection_kwargs
else:
connection = queue.connection.connection_pool.connection_kwargs
conn_key = f"{connection['host']}:{connection.get('port', 6379)}/{connection.get('db', 0)}"
if conn_key not in schedulers:
try:
Expand Down

0 comments on commit e3fefdb

Please sign in to comment.