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
7 changes: 6 additions & 1 deletion imap_data_access/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,13 @@ def _reprocess_parser(args: argparse.Namespace):
for key, value in vars(args).items()
if key in valid_args and value is not None
}
imap_data_access.reprocess(**reprocess_params)
reprocess_id = imap_data_access.reprocess(**reprocess_params)
print("Successfully triggered reprocessing for the given parameters.")
if reprocess_id:
print(
f"Reprocess ID: {reprocess_id} "
f"(filter Dagster runs by tag imap/reprocess_id={reprocess_id})"
)


# PLR0915: too many statements
Expand Down
11 changes: 10 additions & 1 deletion imap_data_access/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def reprocess(
instrument: Optional[str] = None,
data_level: Optional[str] = None,
descriptor: Optional[str] = None,
):
) -> Optional[str]:
"""Trigger reprocessing of files in the IMAP data archive.

Start date and end date are required for a reprocessing Event. If data_level is
Expand All @@ -465,6 +465,13 @@ def reprocess(
Data level (e.g. ``l1a``)
descriptor : str, optional
Descriptor of the data product / product name (e.g. ``burst``)

Returns
-------
str or None
ID of the reprocessing request, which is attached to the resulting
Dagster runs as the ``imap/reprocess_id`` tag. None if the server
did not return one.
"""
# locals() gives us the keyword arguments passed to the function
# and allows us to filter out the None values
Expand Down Expand Up @@ -524,6 +531,8 @@ def reprocess(
items = response.json()
logger.debug("Received JSON: %s", items)

return items.get("reprocess_id") if isinstance(items, dict) else None


def upload(file_path: Union[Path, str]) -> None:
"""Upload a file to the data archive.
Expand Down
9 changes: 9 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,12 @@ def test_cli_error_message(capsys):
cli.main()
captured = capsys.readouterr()
assert "FileNotFoundError" in captured.err


def test_cli_reprocess(capsys):
"""Test that the CLI reprocess command prints the reprocess ID."""
args = Namespace(start_date="20260101", end_date="20260102")
with mock.patch("imap_data_access.reprocess", return_value="test-id"):
cli._reprocess_parser(args)
captured = capsys.readouterr()
assert "Reprocess ID: test-id" in captured.out
7 changes: 5 additions & 2 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,13 @@ def test_reprocess(mock_send_request, reprocess_params: dict):
Dictionary of key/value pairs that set the reprocessing parameters
"""
mock_response = MagicMock()
mock_response.json.return_value = []
mock_response.json.return_value = {
"message": "Reprocess job queued",
"reprocess_id": "test-id",
}
mock_send_request.return_value = mock_response

imap_data_access.reprocess(**reprocess_params)
assert imap_data_access.reprocess(**reprocess_params) == "test-id"

# Should have only been one call to send
mock_send_request.assert_called_once()
Expand Down
Loading