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

Handle the case where the connection to redis instances use Sentinels in get_scheduler_statistics() #671

Merged
merged 1 commit into from
Sep 30, 2024

Conversation

alaouimehdi1995
Copy link
Contributor

@alaouimehdi1995 alaouimehdi1995 commented Sep 3, 2024

When using Sentinels connection to Redis instead of a "single host", when displaying the views.stats view, the following exception is raised:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/views/decorators/cache.py", line 62, in _wrapper_view_func
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapper_view
    return view_func(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django_rq/views.py", line 37, in stats
    **get_scheduler_statistics(),
      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django_rq/utils.py", line 106, in get_scheduler_statistics
    conn_key = f"{connection['host']}:{connection.get('port', 6379)}/{connection.get('db', 0)}"
                  ^^^^^^^^^^^^^^^^^^

Exception Type: KeyError at /admin/background-tasks/
Exception Value: 'host'

The current pull request solves the issue by adding condition on the type of ConnectionPool to redis, then fetching connection_kwargs accordingly.

Created issue: #672

@alaouimehdi1995 alaouimehdi1995 force-pushed the master branch 3 times, most recently from d7a8352 to f2c115c Compare September 3, 2024 12:58
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.
@selwin selwin merged commit 77bc4ff into rq:master Sep 30, 2024
15 checks passed
@selwin
Copy link
Collaborator

selwin commented Sep 30, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants