mirror of https://github.com/rq/rq.git
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
This commit is contained in:
parent
d90c00501e
commit
55f833ab6f
|
@ -19,7 +19,7 @@ from .defaults import DEFAULT_RESULT_TTL
|
|||
from .exceptions import DequeueTimeout, NoSuchJobError
|
||||
from .job import Job, JobStatus
|
||||
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')
|
||||
|
@ -29,9 +29,6 @@ blue = make_colorizer('darkblue')
|
|||
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",
|
||||
"result_ttl", "ttl", "failure_ttl",
|
||||
|
|
12
rq/utils.py
12
rq/utils.py
|
@ -125,6 +125,18 @@ class ColorizingStreamHandler(logging.StreamHandler):
|
|||
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):
|
||||
if v is None:
|
||||
return None
|
||||
|
|
|
@ -45,7 +45,7 @@ from .scheduler import RQScheduler
|
|||
from .suspension import is_suspended
|
||||
from .timeouts import JobTimeoutException, HorseMonitorTimeoutException, UnixSignalDeathPenalty
|
||||
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 .worker_registration import clean_worker_registry, get_keys
|
||||
from .serializers import resolve_serializer
|
||||
|
@ -67,9 +67,6 @@ class StopRequested(Exception):
|
|||
pass
|
||||
|
||||
|
||||
def compact(a_list):
|
||||
return [x for x in a_list if x is not None]
|
||||
|
||||
|
||||
_signames = dict((getattr(signal, signame), signame)
|
||||
for signame in dir(signal)
|
||||
|
|
Loading…
Reference in New Issue