Skip to content

Commit

Permalink
add sequence state service to record status change
Browse files Browse the repository at this point in the history
  • Loading branch information
raylrui committed Dec 3, 2024
1 parent 37f7c7c commit 1b99ea9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 1b99ea9

Please sign in to comment.