diff --git a/libs/libcommon/src/libcommon/queue/past_jobs.py b/libs/libcommon/src/libcommon/queue/past_jobs.py index deb62efee1..0da1e0608f 100644 --- a/libs/libcommon/src/libcommon/queue/past_jobs.py +++ b/libs/libcommon/src/libcommon/queue/past_jobs.py @@ -6,7 +6,6 @@ from typing import Generic, TypeVar from mongoengine import Document -from mongoengine.errors import ValidationError from mongoengine.fields import DateTimeField, IntField, StringField from mongoengine.queryset.queryset import QuerySet @@ -74,10 +73,6 @@ class PastJobDocument(Document): objects = QuerySetManager["PastJobDocument"]() -class NegativeDurationError(ValidationError): - pass - - def create_past_job(dataset: str, started_at: datetime, finished_at: datetime) -> None: """Create a past job in the mongoDB database. @@ -88,17 +83,11 @@ def create_past_job(dataset: str, started_at: datetime, finished_at: datetime) - dataset (`str`): The dataset on which to apply the job. started_at (`datetime`): The date the job has started. finished_at (`datetime`): The date the job has finished. - - Raises: - ValidationError: If the duration is negative. """ duration = int((finished_at - started_at).total_seconds()) if duration < JOB_DURATION_MIN_SECONDS: return - try: - PastJobDocument(dataset=dataset, duration=duration, finished_at=finished_at).save() - except ValidationError as e: - raise NegativeDurationError("The duration of the job cannot be negative.") from e + PastJobDocument(dataset=dataset, duration=duration, finished_at=finished_at).save() if not is_blocked(dataset) and duration > JOB_DURATION_CHECK_MIN_SECONDS: if PastJobDocument.objects(dataset=dataset).sum("duration") > DATASET_BLOCKAGE_THRESHOLD_SECONDS: diff --git a/libs/libcommon/tests/queue/test_past_jobs.py b/libs/libcommon/tests/queue/test_past_jobs.py index 95fa09dea0..65f5a78b5a 100644 --- a/libs/libcommon/tests/queue/test_past_jobs.py +++ b/libs/libcommon/tests/queue/test_past_jobs.py @@ -11,7 +11,6 @@ from libcommon.queue.past_jobs import ( DATASET_BLOCKAGE_THRESHOLD_SECONDS, JOB_DURATION_MIN_SECONDS, - NegativeDurationError, PastJobDocument, create_past_job, ) @@ -50,14 +49,6 @@ def test_create_past_job_with_short_duration(duration: float) -> None: PastJobDocument.objects(dataset=DATASET).count() == 0 -@pytest.mark.parametrize("duration", [-1.0]) -def test_create_past_job_raises(duration: float) -> None: - finished_at = get_datetime() - started_at = finished_at - timedelta(seconds=duration) - with pytest.raises(NegativeDurationError): - create_past_job(dataset=DATASET, started_at=started_at, finished_at=finished_at) - - def test_create_past_job_raises_if_timezone_unaware() -> None: finished_at = get_datetime()