diff --git a/mindee/client_v2.py b/mindee/client_v2.py index 07c19418..268ba3ba 100644 --- a/mindee/client_v2.py +++ b/mindee/client_v2.py @@ -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() @@ -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 @@ -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 ) diff --git a/mindee/parsing/v2/job.py b/mindee/parsing/v2/job.py index 3b43f0de..662efbbc 100644 --- a/mindee/parsing/v2/job.py +++ b/mindee/parsing/v2/job.py @@ -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 @@ -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"] diff --git a/tests/data b/tests/data index 4fd64fdd..c2e36f5b 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit 4fd64fdd462c5f29e49b24aacf6e74c7d9aa1ab3 +Subproject commit c2e36f5b635386cb9bb922b517c4e02039b0a122 diff --git a/tests/v2/parsing/test_job_response.py b/tests/v2/parsing/test_job_response.py index a7f52d3e..2217ebad 100644 --- a/tests/v2/parsing/test_job_response.py +++ b/tests/v2/parsing/test_job_response.py @@ -1,4 +1,5 @@ import json +from datetime import datetime import pytest @@ -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 @@ -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-")