From 0c622d9a4a36ccb7d23501ca5623d5cb6f587788 Mon Sep 17 00:00:00 2001 From: Matic Lubej Date: Wed, 31 Jul 2024 17:09:08 +0200 Subject: [PATCH 1/2] add a waiting section for batch job status update --- sentinelhub/api/batch/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sentinelhub/api/batch/utils.py b/sentinelhub/api/batch/utils.py index be841d2c..fe2982d8 100644 --- a/sentinelhub/api/batch/utils.py +++ b/sentinelhub/api/batch/utils.py @@ -93,6 +93,13 @@ def monitor_batch_job( failed_tiles_num = finished_count - success_count if failed_tiles_num: LOGGER.info("Batch job failed for %d tiles", failed_tiles_num) + + LOGGER.info("Waiting on batch job status update.") + while batch_request.status is BatchRequestStatus.PROCESSING: + time.sleep(sleep_time) + batch_request = batch_client.get_request(batch_request) + + LOGGER.info("Batch job finished with status %s", batch_request.status.value) return tiles_per_status From f5e913e02130861a08758f682a7adffa509e18a7 Mon Sep 17 00:00:00 2001 From: Matic Lubej Date: Thu, 1 Aug 2024 11:17:25 +0200 Subject: [PATCH 2/2] mock also the batch request update part, fix log and sleep call counts --- tests/api/batch/test_utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/api/batch/test_utils.py b/tests/api/batch/test_utils.py index 006d10eb..437c4275 100644 --- a/tests/api/batch/test_utils.py +++ b/tests/api/batch/test_utils.py @@ -73,6 +73,10 @@ def test_monitor_batch_process_job( monitor_analysis_mock = mocker.patch("sentinelhub.api.batch.utils.monitor_batch_analysis") monitor_analysis_mock.return_value = batch_request + updated_batch_request = BatchRequest.from_dict({**batch_request.to_dict(), "status": BatchRequestStatus.DONE}) + batch_request_update_mock = mocker.patch("sentinelhub.SentinelHubBatch.get_request") + batch_request_update_mock.return_value = updated_batch_request + batch_tiles_mock = mocker.patch("sentinelhub.SentinelHubBatch.iter_tiles") batch_tiles_mock.side_effect = tiles_sequence @@ -94,12 +98,12 @@ def test_monitor_batch_process_job( assert batch_tiles_mock.call_count == progress_loop_counts + 1 assert all(call.args == (batch_request,) and call.kwargs == {} for call in batch_tiles_mock.mock_calls) - assert sleep_mock.call_count == progress_loop_counts + assert sleep_mock.call_count == progress_loop_counts + batch_request_update_mock.call_count assert all(call.args == (sleep_time,) and call.kwargs == {} for call in sleep_mock.mock_calls) is_processing_logged = batch_status is BatchRequestStatus.PROCESSING is_failure_logged = BatchTileStatus.FAILED in tile_status_sequence[-1] - assert logging_mock.call_count == int(is_processing_logged) + int(is_failure_logged) + assert logging_mock.call_count == int(is_processing_logged) + int(is_failure_logged) + 2 def _tile_status_counts_to_tiles(tile_status_counts: dict[BatchTileStatus, int]) -> list[dict[str, str]]: