diff --git a/lib/workload/stateless/stacks/sequence-run-manager/sequence_run_manager_proc/lambdas/bssh_event.py b/lib/workload/stateless/stacks/sequence-run-manager/sequence_run_manager_proc/lambdas/bssh_event.py index f365f0998..7c7ae2497 100644 --- a/lib/workload/stateless/stacks/sequence-run-manager/sequence_run_manager_proc/lambdas/bssh_event.py +++ b/lib/workload/stateless/stacks/sequence-run-manager/sequence_run_manager_proc/lambdas/bssh_event.py @@ -13,7 +13,7 @@ SequenceRule, SequenceRuleError, ) -from sequence_run_manager_proc.services import sequence_srv +from sequence_run_manager_proc.services import sequence_srv, sequence_state_srv from libumccr import libjson from libumccr.aws import libeb @@ -109,6 +109,7 @@ def event_handler(event, context): if sequence_domain.state_has_changed: try: SequenceRule(sequence_domain.sequence).must_not_emergency_stop() + sequence_state_srv.create_sequence_state_from_bssh_event(event_details) entry = sequence_domain.to_put_events_request_entry( event_bus_name=event_bus_name, ) @@ -118,7 +119,7 @@ def event_handler(event, context): reason = f"Aborted pipeline due to {se}" logger.warning(reason) - # Dispatch all event entries in one-go! libeb will take care of batching them up for efficiency. + # Dispatch event entry using libeb. if entry: libeb.emit_event(entry) diff --git a/lib/workload/stateless/stacks/sequence-run-manager/sequence_run_manager_proc/services/sequence_state_srv.py b/lib/workload/stateless/stacks/sequence-run-manager/sequence_run_manager_proc/services/sequence_state_srv.py new file mode 100644 index 000000000..c70c11020 --- /dev/null +++ b/lib/workload/stateless/stacks/sequence-run-manager/sequence_run_manager_proc/services/sequence_state_srv.py @@ -0,0 +1,35 @@ +import logging + +from django.db import transaction +from django.db.models import QuerySet + +from sequence_run_manager.models.sequence import Sequence +from sequence_run_manager.models.state import State + + +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) + +@transaction.atomic +def create_sequence_state_from_bssh_event(payload: dict) -> None: + """ + Create SequenceState record from BSSH Run event payload + + { + "dateModified": "2022-06-24T05:07:53.476767Z", + "instrumentRunId": "200508_A01052_0001_BH5LY7ACGT", + "status": "PendingAnalysis" + ... + } + """ + status = payload["status"] + timestamp = payload["dateModified"] + + # get sequence by instrument_run_id + instrument_run_id = payload["instrumentRunId"] + sequence = Sequence.objects.get(instrument_run_id=instrument_run_id) + + # comment for any future usage, None by default + comment = None + + State.objects.create(status=status, timestamp=timestamp, sequence=sequence, comment=comment) \ No newline at end of file