Skip to content

Commit

Permalink
Gracefully handle missing task ID
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlogic committed Aug 26, 2023
1 parent 6cf2995 commit 8166c73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion judoscale/celery/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ def collect(self) -> List[Metric]:
Metric.for_queue(queue_name=queue, oldest_job_ts=published_at)
)
else:
task_id = task.get("id", None)
logger.warning(
"Unable to find `published_at` in task properties for "
f"task ID {task['id']}."
f"task ID {task_id}."
)
else:
metrics.append(
Expand Down
9 changes: 9 additions & 0 deletions tests/test_collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ def test_collect_missing_published_at(self, worker_1, celery):
collector = CeleryMetricsCollector(worker_1, celery)
assert len(collector.collect()) == 0

def test_collect_missing_published_at_and_id(self, worker_1, celery):
celery.connection_for_read().channel().client.scan_iter.return_value = [b"foo"]
celery.connection_for_read().channel().client.lindex.return_value = bytes(
json.dumps({"properties": {}}), "utf-8"
)

collector = CeleryMetricsCollector(worker_1, celery)
assert len(collector.collect()) == 0

def test_collect_response_error(self, worker_1, celery, caplog):
celery.connection_for_read().channel().client.scan_iter.return_value = [b"foo"]
celery.connection_for_read().channel().client.lindex.side_effect = (
Expand Down

0 comments on commit 8166c73

Please sign in to comment.