Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ jobs:
- name: Test with pytest
run: poetry run pytest

# The lock file has RQ 3; also run the tests against RQ 2.
- name: Test with pytest (RQ 2)
run: poetry run pip install "rq>=2,<3" && poetry run pytest

- name: Test django sample app
run: cd ./sample-apps/django_sample && poetry install --all-extras --no-interaction && bin/test

Expand Down
11 changes: 5 additions & 6 deletions judoscale/rq/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _busy_jobs(self, queue: Queue) -> Optional[Tuple[int, Optional[float]]]:
entries = self.redis.zrangebyscore(registry.key, f"({time.time()}", "+inf")
pipeline = self.redis.pipeline()
for entry in entries:
# RQ 2 stores `<job_id>:<execution_id>` entries, RQ 1 job IDs.
# RQ 2+ stores `<job_id>:<execution_id>` entries, RQ 1 job IDs.
job_id = entry.decode().split(":")[0]
pipeline.hget(Job.key_for(job_id), "started_at")
# RQ 1 parses to a naive datetime, though the time is in UTC.
Expand Down Expand Up @@ -111,11 +111,10 @@ def collect(self) -> List[Metric]:

if job := self.oldest_job(queue):
if job.enqueued_at is not None:
# RQ stores `enqueued_at` as a naive datetime object, which
# means it doesn't have any timezone information associated
# with it.
# But since the time is, in fact, in UTC, we can just replace
# the timezone with UTC and then convert it to a timestamp.
# `enqueued_at` is in UTC, but RQ before 2.2 returns it as a
# naive datetime, so set the timezone to UTC before converting
# it to a timestamp. RQ 2.2+ already returns it in UTC, so this
# leaves it unchanged.
# https://github.com/rq/rq/blob/42ac7d4150951b5f5fba8be11573920c1e6f6e69/rq/queue.py#L1003
#
enqueued_at = job.enqueued_at.replace(
Expand Down
27 changes: 21 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ django = { version = ">=2.1.0,<7.0.0", optional = true }
flask = { version = ">=1.1.0,<4.0.0", optional = true }
celery = { version = ">=4.4.0,<6.0.0", extras = ["redis"], optional = true }
dramatiq = { version = ">=1.13.0,<3.0.0", extras = ["redis"], optional = true }
rq = { version = ">=1.0.0,<3.0.0", optional = true }
rq = { version = ">=1.0.0,<4.0.0", optional = true }

[tool.poetry.group.dev.dependencies]
black = "^26.5.1"
Expand Down
99 changes: 78 additions & 21 deletions sample-apps/flask_rq_sample/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sample-apps/flask_rq_sample/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
Flask = "^2.2.3"
rq = "^1.13.0"
rq = "^3.0.0"
gunicorn = "^20.1.0"
judoscale = { path = "../../", extras=["rq", "flask"], develop = true }

Expand Down
7 changes: 4 additions & 3 deletions tests/test_collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import redis.exceptions
import rq.utils as rq_utils
from pytest import approx, fixture, raises
from rq.job import Job

from judoscale.celery.collector import CeleryMetricsCollector
from judoscale.core.metric import Metric
Expand Down Expand Up @@ -931,9 +932,9 @@ def test_collect_with_busy_job_tracking(self, worker_1):
redis.zremrangebyscore.assert_not_called()
hgets = redis.pipeline.return_value.hget.call_args_list
assert [c.args for c in hgets] == [
(b"rq:job:job1", "started_at"),
(b"rq:job:job2", "started_at"),
(b"rq:job:job3", "started_at"),
(Job.key_for("job1"), "started_at"),
(Job.key_for("job2"), "started_at"),
(Job.key_for("job3"), "started_at"),
]

assert metrics[2].measurement == "qt"
Expand Down
Loading