From 0f4d288ceda56adfe2d4f1c0ca34636f97a6ecc0 Mon Sep 17 00:00:00 2001 From: Slava Skvortsov Date: Sun, 8 Nov 2020 18:56:55 +0100 Subject: [PATCH] Small tweaks + add ARQ_DESERIALIZER setting --- Makefile | 2 +- arq_admin/queue.py | 10 +++++++--- arq_admin/settings.py | 2 ++ requirements-dev.txt | 4 ++-- requirements.txt | 4 ++-- setup.cfg | 4 ++++ 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 300fb0a..01e68ea 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ requirements: pip install -r requirements-dev.txt test: - pytest --cov=arq_admin --cov-fail-under 100 + python -m pytest coverage-collect: coverage run -m pytest diff --git a/arq_admin/queue.py b/arq_admin/queue.py index 5761e65..6326d4a 100644 --- a/arq_admin/queue.py +++ b/arq_admin/queue.py @@ -5,10 +5,11 @@ from arq import ArqRedis from arq.connections import RedisSettings, create_pool +from arq.constants import result_key_prefix from arq.jobs import DeserializationError, Job as ArqJob, JobDef, JobStatus +from arq_admin import settings from arq_admin.job import JobInfo -from arq_admin.settings import ARQ_QUEUES class QueueStats(NamedTuple): @@ -34,13 +35,15 @@ class Queue: def from_name(cls, name: str) -> 'Queue': return cls( name=name, - redis_settings=ARQ_QUEUES[name], + redis_settings=settings.ARQ_QUEUES[name], ) async def get_jobs(self, status: Optional[JobStatus] = None) -> List[JobInfo]: redis = await create_pool(self.redis_settings) job_ids = set(await redis.zrangebyscore(self.name)) - job_ids |= {job_result.job_id for job_result in await redis.all_job_results()} + result_keys = await redis.keys(f'{result_key_prefix}*') + job_ids |= {key[len(result_key_prefix):] for key in result_keys} + jobs: List[JobInfo] = await asyncio.gather(*[self.get_job_by_id(job_id, redis) for job_id in job_ids]) if status: @@ -76,6 +79,7 @@ async def get_job_by_id(self, job_id: str, redis: Optional[ArqRedis] = None) -> job_id=job_id, redis=redis, _queue_name=self.name, + _deserializer=settings.ARQ_DESERIALIZER, ) unknown_function_msg = "Can't find job" diff --git a/arq_admin/settings.py b/arq_admin/settings.py index d1ef45b..32d7169 100644 --- a/arq_admin/settings.py +++ b/arq_admin/settings.py @@ -8,3 +8,5 @@ if not all(isinstance(redis_settings, RedisSettings) for redis_settings in ARQ_QUEUES.values()): raise ImproperlyConfigured('All values of "ARQ_QUEUES" must be RedisSettings') + +ARQ_DESERIALIZER = getattr(settings, 'ARQ_DESERIALIZER', None) diff --git a/requirements-dev.txt b/requirements-dev.txt index 6d58634..45c1056 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -14,13 +14,13 @@ cognitive-complexity==1.2.0 mccabe==0.6.1 flake8==3.8.4 flake8-blind-except==0.1.1 -flake8-broken-line==0.2.1 +flake8-broken-line==0.3.0 flake8-bugbear==20.1.4 flake8-builtins==1.5.3 flake8-class-attributes-order==0.1.1 flake8-cognitive-complexity==0.1.0 flake8-commas==2.0.0 -flake8-comprehensions==3.2.3 +flake8-comprehensions==3.3.0 flake8-debugger==3.2.1 flake8-eradicate==1.0.0 flake8-functions==0.0.4 diff --git a/requirements.txt b/requirements.txt index f4c595e..8513205 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -arq==0.19 -Django==3.1.2 +arq==0.19.1 +Django==3.1.3 diff --git a/setup.cfg b/setup.cfg index 10a994e..d1fbe09 100644 --- a/setup.cfg +++ b/setup.cfg @@ -64,6 +64,9 @@ DJANGO_SETTINGS_MODULE = arq_admin.tests.settings django_find_project = false filterwarnings = error junit_family = xunit1 +addopts = + --cov=arq_admin + --cov-fail-under 100 [coverage:run] source = arq_admin @@ -72,6 +75,7 @@ branch = True omit = arq_admin/tests/* arq_admin/settings.py + arq_admin/apps.py [coverage:html] directory = cov_html