|
2 | 2 | from math import ceil |
3 | 3 | from typing import Tuple, Optional |
4 | 4 |
|
5 | | -import redis |
6 | 5 | from django.contrib import admin, messages |
7 | 6 | from django.contrib.admin.views.decorators import staff_member_required |
8 | 7 | from django.core.paginator import Paginator |
|
14 | 13 | from django.views.decorators.cache import never_cache |
15 | 14 | from redis.exceptions import ResponseError |
16 | 15 |
|
17 | | -from .queues import get_all_workers, get_connection, QueueNotFoundError |
| 16 | + |
| 17 | +from .queues import get_all_workers, get_connection, QueueNotFoundError, ConnectionErrors |
18 | 18 | from .queues import get_queue as get_queue_base |
19 | 19 | from .rq_classes import JobExecution, DjangoWorker, DjangoQueue, InvalidJobOperation |
20 | 20 | from .settings import SCHEDULER_CONFIG, logger |
21 | 21 |
|
22 | 22 |
|
| 23 | +try: |
| 24 | + from valkey import exceptions |
| 25 | +except ImportError: |
| 26 | + exceptions = "" |
| 27 | + exceptions.ResponseError = ResponseError |
| 28 | + |
| 29 | +ResponseErrors = (ResponseError, exceptions.ResponseError) |
| 30 | + |
| 31 | + |
23 | 32 | def get_queue(queue_name: str) -> DjangoQueue: |
24 | 33 | try: |
25 | 34 | return get_queue_base(queue_name) |
@@ -71,7 +80,7 @@ def get_statistics(run_maintenance_tasks=False): |
71 | 80 | if run_maintenance_tasks: |
72 | 81 | queue.clean_registries() |
73 | 82 |
|
74 | | - # Raw access to the first item from left of the redis list. |
| 83 | + # Raw access to the first item from left of the broker list. |
75 | 84 | # This might not be accurate since new job can be added from the left |
76 | 85 | # with `at_front` parameters. |
77 | 86 | # Ideally rq should supports Queue.oldest_job |
@@ -102,7 +111,7 @@ def get_statistics(run_maintenance_tasks=False): |
102 | 111 | canceled_jobs=len(queue.canceled_job_registry), |
103 | 112 | ) |
104 | 113 | queues.append(queue_data) |
105 | | - except redis.ConnectionError as e: |
| 114 | + except ConnectionErrors as e: |
106 | 115 | logger.error(f"Could not connect for queue {queue_name}: {e}") |
107 | 116 | continue |
108 | 117 |
|
@@ -277,7 +286,7 @@ def clear_queue_registry(request: HttpRequest, queue_name: str, registry_name: s |
277 | 286 | for job_id in job_ids: |
278 | 287 | registry.remove(job_id, delete_job=True) |
279 | 288 | messages.info(request, f"You have successfully cleared the {registry_name} jobs in queue {queue.name}") |
280 | | - except ResponseError as e: |
| 289 | + except ResponseErrors as e: |
281 | 290 | messages.error( |
282 | 291 | request, |
283 | 292 | f"error: {e}", |
|
0 commit comments