From bbf6c39bc11abc17db6e1890958ed4a1af3d6f50 Mon Sep 17 00:00:00 2001 From: william Date: Mon, 23 Sep 2024 14:26:15 +1000 Subject: [PATCH] Events in custom-csv loader --- .../proc/service/load_csv_srv.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/workload/stateless/stacks/metadata-manager/proc/service/load_csv_srv.py b/lib/workload/stateless/stacks/metadata-manager/proc/service/load_csv_srv.py index f1a49164b..8bd75d16a 100644 --- a/lib/workload/stateless/stacks/metadata-manager/proc/service/load_csv_srv.py +++ b/lib/workload/stateless/stacks/metadata-manager/proc/service/load_csv_srv.py @@ -9,6 +9,8 @@ from app.models.sample import Source from app.models.utils import get_value_from_human_readable_label from proc.service.utils import clean_model_history +from app.serializers import LibrarySerializer +from proc.aws.event.event import MetadataStateChangeEvent logger = logging.getLogger() logger.setLevel(logging.INFO) @@ -25,6 +27,9 @@ def load_metadata_csv(df: pd.DataFrame): """ logger.info(f"Start processing LabMetadata") + # Event entries for the event bus + event_bus_entries = list() + # Used for statistics invalid_data = [] stats = { @@ -52,7 +57,6 @@ def load_metadata_csv(df: pd.DataFrame): "contact": { "create_count": 0, "update_count": 0, - "delete_count": 0, }, 'invalid_record_count': 0, } @@ -201,11 +205,29 @@ def load_metadata_csv(df: pd.DataFrame): 'subject_id': subject.orcabus_id, } ) + + lib_dict = LibrarySerializer(library).data if is_lib_created: stats['library']['create_count'] += 1 + event = MetadataStateChangeEvent( + action='CREATE', + model='LIBRARY', + ref_id=lib_dict.get('orcabus_id'), + data=lib_dict + ) + event_bus_entries.append(event.get_put_event_entry()) + if is_lib_updated: stats['library']['update_count'] += 1 + event = MetadataStateChangeEvent( + action='UPDATE', + model='LIBRARY', + ref_id=lib_dict.get('orcabus_id'), + data=lib_dict, + ) + event_bus_entries.append(event.get_put_event_entry()) + # link library to its project if project: try: