Moves the `compact` helper to `utils` (#1769)

* Moves the `compact` helper to `utils`

There is a helper funcion that excludes `None` values
from a list. This was being declared both in the Queue
and in the worker. This centralizes this helper in the `utils`
Importing

* Fix Type Annotation
main
lowercase00 2 years ago committed by GitHub
parent d90c00501e
commit 55f833ab6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,7 +19,7 @@ from .defaults import DEFAULT_RESULT_TTL
from .exceptions import DequeueTimeout, NoSuchJobError from .exceptions import DequeueTimeout, NoSuchJobError
from .job import Job, JobStatus from .job import Job, JobStatus
from .serializers import resolve_serializer from .serializers import resolve_serializer
from .utils import backend_class, get_version, import_attribute, make_colorizer, parse_timeout, utcnow from .utils import backend_class, get_version, import_attribute, make_colorizer, parse_timeout, utcnow, compact
green = make_colorizer('darkgreen') green = make_colorizer('darkgreen')
@ -29,9 +29,6 @@ blue = make_colorizer('darkblue')
logger = logging.getLogger("rq.queue") logger = logging.getLogger("rq.queue")
def compact(lst):
return [item for item in lst if item is not None]
class EnqueueData(namedtuple('EnqueueData', ["func", "args", "kwargs", "timeout", class EnqueueData(namedtuple('EnqueueData', ["func", "args", "kwargs", "timeout",
"result_ttl", "ttl", "failure_ttl", "result_ttl", "ttl", "failure_ttl",

@ -125,6 +125,18 @@ class ColorizingStreamHandler(logging.StreamHandler):
return message return message
def compact(lst: t.List[t.Any]) -> t.List[t.Any]:
"""Excludes `None` values from a list-like object.
Args:
lst (list): A list (or list-like) oject
Returns:
object (list): The list without None values
"""
return [item for item in lst if item is not None]
def as_text(v): def as_text(v):
if v is None: if v is None:
return None return None

@ -45,7 +45,7 @@ from .scheduler import RQScheduler
from .suspension import is_suspended from .suspension import is_suspended
from .timeouts import JobTimeoutException, HorseMonitorTimeoutException, UnixSignalDeathPenalty from .timeouts import JobTimeoutException, HorseMonitorTimeoutException, UnixSignalDeathPenalty
from .utils import (backend_class, ensure_list, get_version, from .utils import (backend_class, ensure_list, get_version,
make_colorizer, utcformat, utcnow, utcparse) make_colorizer, utcformat, utcnow, utcparse, compact)
from .version import VERSION from .version import VERSION
from .worker_registration import clean_worker_registry, get_keys from .worker_registration import clean_worker_registry, get_keys
from .serializers import resolve_serializer from .serializers import resolve_serializer
@ -67,9 +67,6 @@ class StopRequested(Exception):
pass pass
def compact(a_list):
return [x for x in a_list if x is not None]
_signames = dict((getattr(signal, signame), signame) _signames = dict((getattr(signal, signame), signame)
for signame in dir(signal) for signame in dir(signal)

Loading…
Cancel
Save