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
9 changes: 7 additions & 2 deletions mindee/client_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def get_result(
:param response_type: Class of the product to instantiate.
:return: An inference response.
"""
logger.debug("Fetching inference: %s", inference_id)
logger.debug("Fetching result: %s", inference_id)

response = self.mindee_api.req_get_inference(
inference_id, response_type.get_result_slug()
Expand Down Expand Up @@ -152,7 +152,7 @@ def enqueue_and_get_result(
)
enqueue_response = self.enqueue_inference(input_source, params, True)
logger.debug(
"Successfully enqueued document with job id: %s", enqueue_response.job.id
"Successfully enqueued document with job ID: %s", enqueue_response.job.id
)
sleep(params.polling_options.initial_delay_sec)
try_counter = 0
Expand All @@ -168,6 +168,11 @@ def enqueue_and_get_result(
f"Parsing failed for job {job_response.job.id}: {detail}"
)
if job_response.job.status == CommonStatus.PROCESSED.value:
logger.debug(
"Job ID %s completed processing at: %s",
job_response.job.id,
job_response.job.completed_at,
)
result = self.get_result(
response_type or InferenceResponse, job_response.job.id
)
Expand Down
9 changes: 8 additions & 1 deletion mindee/parsing/v2/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class Job:
error: Optional[ErrorResponse]
"""Error response if any."""
created_at: datetime
"""Timestamp of the job creation."""
"""Date and time of the Job creation."""
completed_at: Optional[datetime] = None
"""Date and time of the Job completion. Filled once processing is finished."""
model_id: str
"""ID of the model."""
filename: str
Expand All @@ -39,6 +41,11 @@ def __init__(self, raw_response: StringDict) -> None:
self.created_at = datetime.fromisoformat(
raw_response["created_at"].replace("Z", "+00:00")
)
completed_at = raw_response.get("completed_at")
if completed_at:
self.completed_at = datetime.fromisoformat(
completed_at.replace("Z", "+00:00")
)
self.model_id = raw_response["model_id"]
self.polling_url = raw_response["polling_url"]
self.filename = raw_response["filename"]
Expand Down
2 changes: 1 addition & 1 deletion tests/data
18 changes: 18 additions & 0 deletions tests/v2/parsing/test_job_response.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from datetime import datetime

import pytest

Expand All @@ -21,6 +22,20 @@ def test_should_load_when_status_is_processing():
response = JobResponse(json_sample)

assert response.job is not None
assert response.job.status == "Processing"
assert response.job.completed_at is None
assert response.job.error is None


@pytest.mark.v2
def test_should_load_when_status_is_processed():
"""Should load when status is Processing."""
json_sample = _get_job_samples("ok_processed_webhooks_ok.json")
response = JobResponse(json_sample)

assert response.job is not None
assert response.job.status == "Processed"
assert isinstance(response.job.completed_at, datetime)
assert response.job.error is None


Expand All @@ -31,6 +46,9 @@ def test_should_load_with_422_error():
response = JobResponse(json_sample)

assert response.job is not None
assert response.job.status == "Failed"
assert isinstance(response.job.completed_at, datetime)

assert isinstance(response.job.error, ErrorResponse)
assert response.job.error.status == 422
assert response.job.error.code.startswith("422-")
Expand Down