Skip to content

Commit

Permalink
Small tweaks + add ARQ_DESERIALIZER setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Slava Skvortsov committed Nov 8, 2020
1 parent c9c1d44 commit 0f4d288
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions arq_admin/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions arq_admin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
arq==0.19
Django==3.1.2
arq==0.19.1
Django==3.1.3
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -72,6 +75,7 @@ branch = True
omit =
arq_admin/tests/*
arq_admin/settings.py
arq_admin/apps.py

[coverage:html]
directory = cov_html
Expand Down

0 comments on commit 0f4d288

Please sign in to comment.