-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add sequence state service to record status change
- Loading branch information
Showing
2 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...less/stacks/sequence-run-manager/sequence_run_manager_proc/services/sequence_state_srv.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |