diff --git a/pyvatti/src/pyvatti/helm.py b/pyvatti/src/pyvatti/helm.py index e0cff31..0998c0b 100644 --- a/pyvatti/src/pyvatti/helm.py +++ b/pyvatti/src/pyvatti/helm.py @@ -85,6 +85,7 @@ class GlobflowParams(BaseModel): outdir: str config_application: str config_crypt4gh: str + secret_key: str class Secrets(BaseModel): diff --git a/pyvatti/src/pyvatti/jobstates.py b/pyvatti/src/pyvatti/jobstates.py index 22be90d..03d1d3e 100644 --- a/pyvatti/src/pyvatti/jobstates.py +++ b/pyvatti/src/pyvatti/jobstates.py @@ -2,8 +2,8 @@ class States(str, enum.Enum): - REQUESTED = "requested" - CREATED = "created" - DEPLOYED = "deployed" - FAILED = "failed" - SUCCEEDED = "succeeded" + REQUESTED = "Requested" + CREATED = "Created" + DEPLOYED = "Deployed" + FAILED = "Failed" + SUCCEEDED = "Succeeded" diff --git a/pyvatti/src/pyvatti/notifymodels.py b/pyvatti/src/pyvatti/notifymodels.py index 1d8a576..2cee576 100644 --- a/pyvatti/src/pyvatti/notifymodels.py +++ b/pyvatti/src/pyvatti/notifymodels.py @@ -54,7 +54,7 @@ class SeqeraLog(BaseModel): Parse the seqera status to a job machine state: >>> log.get_job_state() - + A job can take time to start. During this time you'll get empty responses from the Seqera API: @@ -103,23 +103,15 @@ def get_job_state(self) -> Optional[States]: return state -class BackendEvents(str, enum.Enum): - """Events recognised by the backend""" - - STARTED = "started" - ERROR = "error" - COMPLETED = "completed" - - class BackendStatusMessage(BaseModel): """A message updating the backend about job state >>> from datetime import datetime - >>> d = {"run_name": "INTP123456", "utc_time": datetime(1999, 12, 31), "event": BackendEvents.COMPLETED} + >>> d = {"run_name": "INTP123456", "utc_time": datetime(1999, 12, 31), "event": States.DEPLOYED } >>> BackendStatusMessage(**d).model_dump_json() - '{"run_name":"INTP123456","utc_time":"1999-12-31T00:00:00","event":"completed"}' + '{"run_name":"INTP123456","utc_time":"1999-12-31T00:00:00","event":"Deployed"}' """ run_name: str utc_time: PastDatetime - event: BackendEvents + event: States diff --git a/pyvatti/src/pyvatti/pgsjob.py b/pyvatti/src/pyvatti/pgsjob.py index 383f7f2..4a98f6d 100644 --- a/pyvatti/src/pyvatti/pgsjob.py +++ b/pyvatti/src/pyvatti/pgsjob.py @@ -14,7 +14,7 @@ from pyvatti.config import Settings, K8SNamespace from pyvatti.jobstates import States from pyvatti.messagemodels import JobRequest -from pyvatti.notifymodels import SeqeraLog, BackendStatusMessage, BackendEvents +from pyvatti.notifymodels import SeqeraLog, BackendStatusMessage from pyvatti.resources import GoogleResourceHandler, DummyResourceHandler @@ -35,7 +35,7 @@ class PolygenicScoreJob(Machine): On instantiation the default job state is requested: >>> job.state - + Normally creating a resource requires some parameters from a message, but not in dry run mdoe: @@ -56,7 +56,7 @@ class PolygenicScoreJob(Machine): >>> job.trigger("succeed") # doctest: +ELLIPSIS Sending state notification: States.SUCCEEDED - msg='{"run_name":"INT123456","utc_time":...,"event":"completed"}' prepared to send to pipeline-notify topic (PYTEST RUNNING) + msg='{"run_name":"INT123456","utc_time":...,"event":"Succeeded"}' prepared to send to pipeline-notify topic (PYTEST RUNNING) Deleting all resources: INT123456 ... @@ -72,7 +72,7 @@ class PolygenicScoreJob(Machine): >>> bad_job = PolygenicScoreJob("INT789123", dry_run=True) >>> bad_job.trigger("error") # doctest: +ELLIPSIS Sending state notification: States.FAILED - msg='{"run_name":"INT789123","utc_time":"...","event":"error"}' prepared to send to pipeline-notify topic (PYTEST RUNNING) + msg='{"run_name":"INT789123","utc_time":"...","event":"Failed"}' prepared to send to pipeline-notify topic (PYTEST RUNNING) Deleting all resources: INT789123 ... @@ -125,12 +125,6 @@ class PolygenicScoreJob(Machine): States.SUCCEEDED: "succeed", States.DEPLOYED: "deploy", } - # map from states to events recognised by the backend - state_event_map: ClassVar[dict] = { - States.FAILED: BackendEvents.ERROR, - States.SUCCEEDED: BackendEvents.COMPLETED, - States.DEPLOYED: BackendEvents.STARTED, - } def __init__( self, intp_id: str, settings: Optional[Settings] = None, dry_run: bool = False @@ -171,6 +165,7 @@ def __init__( def handle_error(self, event): logger.warning(f"Exception raised for {self.intp_id}") + logger.warning(event.error) if isinstance(event.error, MachineError): logger.warning(f"Couldn't trigger error state for {self.intp_id}") raise event.error @@ -197,9 +192,8 @@ def notify(self, _: EventData): """Notify the backend about the job state""" # bootstrap_server_host: str, bootstrap_server_port: int logger.info(f"Sending state notification: {self.state}") - event: str = self.state_event_map[self.state] msg: str = BackendStatusMessage( - run_name=self.intp_id, utc_time=datetime.now(), event=event + run_name=self.intp_id, utc_time=datetime.now(), event=self.state ).model_dump_json() if "pytest" in sys.modules: logger.info( diff --git a/pyvatti/tests/test_render.py b/pyvatti/tests/test_render.py index e1d7d7a..191e105 100644 --- a/pyvatti/tests/test_render.py +++ b/pyvatti/tests/test_render.py @@ -19,7 +19,7 @@ def test_render(message): """Test a values.yaml helm file is templated and rendered correctly""" settings = Settings( TOWER_TOKEN="test", - TOWER_WORKSPACE="test", + TOWER_WORKSPACE=000000, GLOBUS_DOMAIN="https://example.com", GLOBUS_CLIENT_ID="test", GLOBUS_CLIENT_SECRET="test",