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
2 changes: 1 addition & 1 deletion src/aind_data_transfer_service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import yaml
from pythonjsonlogger import json as log_json

__version__ = "2.1.1"
__version__ = "2.1.2"


# We want to standardize the timestamp format to UTC and ISO-8601, which
Expand Down
21 changes: 20 additions & 1 deletion src/aind_data_transfer_service/log_handler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""Module to handle logging submit job requests"""

import logging
from datetime import datetime
from enum import Enum
from typing import Any

from aind_data_schema_models.data_name_patterns import build_data_name


class EventType(str, Enum):
"""Enum for event types in structured logging"""
Expand All @@ -13,6 +16,22 @@ class EventType(str, Enum):
STAGE_FAILURE = "stage_failure"


def compute_label(upload_job: dict) -> str:
"""Hack to compute acquisition_name from raw user input. This can be
cleaned up in the next major release."""
subject_id = upload_job.get("subject_id")
acq_datetime = datetime.fromisoformat(upload_job.get("acq_datetime"))
platform = upload_job.get("platform")
if platform is not None:
label = f"{platform['abbreviation']}_{subject_id}"
else:
label = subject_id
return build_data_name(
label=label,
creation_datetime=acq_datetime,
)


def log_submit_job_request(
content: Any, event_type: EventType | None = None
) -> None:
Expand All @@ -35,7 +54,7 @@ def log_submit_job_request(
):
for row in upload_jobs:
subject_id = row.get("subject_id")
acquisition_name = row.get("s3_prefix")
acquisition_name = compute_label(row)
extra_info = {
"subject_id": subject_id,
"acquisition_name": acquisition_name,
Expand Down
6 changes: 4 additions & 2 deletions tests/test_log_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class TestLogHandler(unittest.TestCase):
def test_log_submit_job_request(self, mock_log: MagicMock):
"""Tests log_submit_job_request"""
content = {
"upload_jobs": [{"s3_prefix": "abc-123", "subject_id": "123456"}]
"upload_jobs": [
{"acq_datetime": "2026-10-10T00:01:02", "subject_id": "123456"}
]
}
log_submit_job_request(
content=content, event_type=EventType.STAGE_START
Expand All @@ -30,7 +32,7 @@ def test_log_submit_job_request(self, mock_log: MagicMock):
extra={
"event_type": EventType.STAGE_START,
"subject_id": "123456",
"acquisition_name": "abc-123",
"acquisition_name": "123456_2026-10-10_00-01-02",
},
)

Expand Down
Loading