Skip to content

Commit

Permalink
no more need for negative duration test, since we discard durations b…
Browse files Browse the repository at this point in the history
…elow JOB_DURATION_MIN_SECONDS
  • Loading branch information
severo committed Jun 20, 2024
1 parent adf049c commit b0cb05f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 21 deletions.
13 changes: 1 addition & 12 deletions libs/libcommon/src/libcommon/queue/past_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down
9 changes: 0 additions & 9 deletions libs/libcommon/tests/queue/test_past_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from libcommon.queue.past_jobs import (
DATASET_BLOCKAGE_THRESHOLD_SECONDS,
JOB_DURATION_MIN_SECONDS,
NegativeDurationError,
PastJobDocument,
create_past_job,
)
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit b0cb05f

Please sign in to comment.