Skip to content

Commit

Permalink
Fix dataset name when decreasing metrics (#2971)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaFrancis authored Jul 4, 2024
1 parent 3d948fb commit 4da51fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libs/libcommon/src/libcommon/queue/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def delete_waiting_jobs_by_job_id(self, job_ids: list[str]) -> int:
try:
existing = JobDocument.objects(pk__in=job_ids, status=Status.WAITING)
for job in existing.all():
decrease_metric(dataset=job.type, job_type=job.type, status=job.status, difficulty=job.difficulty)
decrease_metric(dataset=job.dataset, job_type=job.type, status=job.status, difficulty=job.difficulty)
deleted_jobs = existing.delete()
return 0 if deleted_jobs is None else deleted_jobs
except Exception:
Expand Down
14 changes: 14 additions & 0 deletions libs/libcommon/tests/queue/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ def test_delete_waiting_jobs_by_job_id_wrong_format() -> None:
assert JobTotalMetricDocument.objects().count() == 0


def test_delete_waiting_jobs_by_job_id_blocked() -> None:
queue = Queue()
job = queue.add_job(job_type="test_type", dataset="dataset", revision="test_revision", difficulty=50)
assert_metric_jobs_per_worker(worker_size=WorkerSize.medium, jobs_count=1)
assert queue.delete_waiting_jobs_by_job_id(job_ids=[job.info()["job_id"]]) == 1
assert_metric_jobs_per_worker(worker_size=WorkerSize.medium, jobs_count=0)

job = queue.add_job(job_type="test_type", dataset="dataset", revision="test_revision", difficulty=100)
block_dataset("dataset")
assert_metric_jobs_per_worker(worker_size=WorkerSize.medium, jobs_count=0)
assert queue.delete_waiting_jobs_by_job_id(job_ids=[job.info()["job_id"]]) == 1
assert_metric_jobs_per_worker(worker_size=WorkerSize.medium, jobs_count=0)


def check_job(queue: Queue, expected_dataset: str, expected_split: str, expected_priority: Priority) -> None:
job_info = queue.start_job()
assert job_info["params"]["dataset"] == expected_dataset
Expand Down

0 comments on commit 4da51fe

Please sign in to comment.