Skip to content

Commit dedcc55

Browse files
committed
feat(scilog): add support for file dimensions in ingest_data method
1 parent 11917f7 commit dedcc55

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

backend/bec_atlas/ingestor/scilog_logbook_manager.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,12 @@ def ingest_data(self, msg: messages.MessagingServiceMessage, logbook_id: str):
190190
with open(file_path, "wb") as f:
191191
f.write(msg_part.data)
192192
files.append(file_path)
193-
scilog_msg.add_file(file_path)
193+
dimensions = {}
194+
if msg_part.width is not None:
195+
dimensions["width"] = msg_part.width
196+
if msg_part.height is not None:
197+
dimensions["height"] = msg_part.height
198+
scilog_msg.add_file(file_path, **dimensions)
194199
elif isinstance(msg_part, messages.MessagingServiceTagsContent):
195200
scilog_msg.add_tag(msg_part.tags)
196201

backend/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies = [
1616
"fastapi[standard]",
1717
"pyjwt",
1818
"pwdlib[argon2]",
19-
"bec_lib",
19+
"bec_lib~=3.112",
2020
"python-socketio[asyncio_client]",
2121
"libtmux",
2222
"websocket-client",
@@ -25,7 +25,7 @@ dependencies = [
2525
"ldap3",
2626
"typer",
2727
"requests",
28-
"scilog~=2.1",
28+
"scilog~=2.3",
2929
]
3030

3131

backend/tests/test_scilog_logbook_manager.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,3 +574,42 @@ def test_ingest_data_file_cleanup_on_error(logbook_manager, mock_scilog, sample_
574574
# Despite the error, directory should exist (failed to clean up the file)
575575
# In this case we expect subdirectories to remain since file removal failed
576576
assert len(list(tmp_path.iterdir())) > 0
577+
578+
579+
@pytest.mark.timeout(60)
580+
@pytest.mark.parametrize(
581+
"width,height",
582+
[(800, 600), (None, 600), (800, None), (None, None), ("800px", "600px"), ("50%", "50%")],
583+
)
584+
def test_ingest_data_file_with_dimensions(
585+
logbook_manager, mock_scilog, sample_logbook, tmp_path, width, height
586+
):
587+
"""Test ingesting a file with dimensions (width and height)."""
588+
mock_scilog.get_logbooks.return_value = [sample_logbook]
589+
mock_message = mock.Mock()
590+
mock_scilog.new.return_value = mock_message
591+
592+
file_data = b"Test image content"
593+
msg = messages.MessagingServiceMessage(
594+
service_name="scilog",
595+
message=[
596+
messages.MessagingServiceFileContent(
597+
filename="image.png",
598+
data=file_data,
599+
mime_type="image/png",
600+
width=width,
601+
height=height,
602+
)
603+
],
604+
scope="deployment_scope",
605+
)
606+
607+
logbook_manager.ingest_data(msg, "logbook_123")
608+
609+
# Verify add_file was called with dimensions
610+
assert mock_message.add_file.call_count == 1
611+
args, kwargs = mock_message.add_file.call_args
612+
if width is not None:
613+
assert "width" in kwargs and kwargs["width"] == width
614+
if height is not None:
615+
assert "height" in kwargs and kwargs["height"] == height

0 commit comments

Comments
 (0)