Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build conn_key from sentinels current master when applicable #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion django_rq/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,18 @@ def get_scheduler_statistics():
# jobs in more than one of them
queue = get_queue_by_index(index)
connection = queue.connection.connection_pool.connection_kwargs
conn_key = f"{connection['host']}:{connection.get('port', 6379)}/{connection.get('db', 0)}"

# When using Sentinel, connection does not have a host key, so build conn_key from all sentinels host:port pairs.
if 'connection_pool' in connection and hasattr(connection['connection_pool'], 'sentinel_manager'):
pool = connection['connection_pool']
master = pool.sentinel_manager.discover_master(pool.service_name)
if master:
conn_key = f"{master[0]}:{master[1]}/{pool.service_name}/{pool.sentinel_manager.connection_kwargs.get('db', 0)}"
else:
continue
else:
conn_key = f"{connection['host']}:{connection.get('port', 6379)}/{connection.get('db', 0)}"

if conn_key not in schedulers:
try:
scheduler = get_scheduler(config['name'])
Expand Down
Loading