Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for batch process API job to update status from PROCESSING to something else #536

Merged
merged 2 commits into from
Aug 1, 2024
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
7 changes: 7 additions & 0 deletions sentinelhub/api/batch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 6 additions & 2 deletions tests/api/batch/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]]:
Expand Down
Loading