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

Fix broken /admin/background-tasks web UI when using Sentinel #670

Closed
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']
sentinels = ','.join([
f"{s.connection_pool.connection_kwargs.get('host')}:{s.connection_pool.connection_kwargs.get('port')}"
for s in pool.sentinel_manager.sentinels
])
conn_key = f"Sentinel({sentinels})://{pool.service_name}/{pool.sentinel_manager.connection_kwargs.get('db', 0)}"
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