From edc93c380fddf18df1e514338a23b7dd3b7b0677 Mon Sep 17 00:00:00 2001 From: Tom Hamilton Stubber Date: Sun, 14 May 2023 01:48:36 +0100 Subject: [PATCH] Stop calling deprecated function (#1908) --- rq/connections.py | 4 ++-- rq/job.py | 10 +++++++--- rq/queue.py | 8 ++++---- rq/registry.py | 8 ++++---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/rq/connections.py b/rq/connections.py index 36d771dc..02b50e3e 100644 --- a/rq/connections.py +++ b/rq/connections.py @@ -1,8 +1,8 @@ import warnings from contextlib import contextmanager -from typing import Any, Optional, Tuple, Type +from typing import Optional, Tuple, Type -from redis import Connection as RedisConnection, Redis, SSLConnection, UnixDomainSocketConnection +from redis import Connection as RedisConnection, Redis from .local import LocalStack diff --git a/rq/job.py b/rq/job.py index 5094b2da..b4ee6a41 100644 --- a/rq/job.py +++ b/rq/job.py @@ -532,9 +532,10 @@ class Job: Returns: job_exists (bool): Whether the Job exists """ - conn = resolve_connection(connection) + if not connection: + connection = resolve_connection() job_key = cls.key_for(job_id) - job_exists = conn.exists(job_key) + job_exists = connection.exists(job_key) return bool(job_exists) @classmethod @@ -587,7 +588,10 @@ class Job: return jobs def __init__(self, id: Optional[str] = None, connection: Optional['Redis'] = None, serializer=None): - self.connection = resolve_connection(connection) + if connection: + self.connection = connection + else: + self.connection = resolve_connection() self._id = id self.created_at = utcnow() self._data = UNEVALUATED diff --git a/rq/queue.py b/rq/queue.py index d8441046..f7a0c878 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -22,7 +22,7 @@ from .connections import resolve_connection from .defaults import DEFAULT_RESULT_TTL from .exceptions import DequeueTimeout, NoSuchJobError from .job import Job, JobStatus -from .logutils import blue, green, yellow +from .logutils import blue, green from .types import FunctionReferenceType, JobDependencyType from .serializers import resolve_serializer from .utils import backend_class, get_version, import_attribute, parse_timeout, utcnow, compact @@ -86,7 +86,7 @@ class Queue: Returns: queues (List[Queue]): A list of all queues. """ - connection = resolve_connection(connection) + connection = connection or resolve_connection() def to_queue(queue_key: Union[bytes, str]): return cls.from_queue_key( @@ -162,7 +162,7 @@ class Queue: serializer (Any, optional): Serializer. Defaults to None. death_penalty_class (Type[BaseDeathPenalty, optional): Job class or a string referencing the Job class path. Defaults to UnixSignalDeathPenalty. """ - self.connection = resolve_connection(connection) + self.connection = connection or resolve_connection() prefix = self.redis_queue_namespace_prefix self.name = name self._key = '{0}{1}'.format(prefix, name) @@ -1198,7 +1198,7 @@ class Queue: Returns: _type_: _description_ """ - connection = resolve_connection(connection) + connection = connection or resolve_connection() if timeout is not None: # blocking variant if timeout == 0: raise ValueError('RQ does not support indefinite timeouts. Please pick a timeout value > 0') diff --git a/rq/registry.py b/rq/registry.py index 2bd874c2..acd6bd72 100644 --- a/rq/registry.py +++ b/rq/registry.py @@ -7,7 +7,7 @@ import time from datetime import datetime, timedelta, timezone from typing import TYPE_CHECKING, Any, List, Optional, Type, Union -from .timeouts import JobTimeoutException, UnixSignalDeathPenalty, BaseDeathPenalty +from .timeouts import UnixSignalDeathPenalty, BaseDeathPenalty if TYPE_CHECKING: from redis import Redis @@ -15,7 +15,7 @@ if TYPE_CHECKING: from .utils import as_text from .connections import resolve_connection -from .defaults import DEFAULT_FAILURE_TTL, CALLBACK_TIMEOUT +from .defaults import DEFAULT_FAILURE_TTL from .exceptions import InvalidJobOperation, NoSuchJobError, AbandonedJobError from .job import Job, JobStatus from .queue import Queue @@ -47,11 +47,11 @@ class BaseRegistry: ): if queue: self.name = queue.name - self.connection = resolve_connection(queue.connection) + self.connection = queue.connection or resolve_connection() self.serializer = queue.serializer else: self.name = name - self.connection = resolve_connection(connection) + self.connection = connection or resolve_connection() self.serializer = resolve_serializer(serializer) self.key = self.key_template.format(self.name)