From 364e45efc68abc406be8676219413649eb27250b Mon Sep 17 00:00:00 2001
From: Daniel Nemergut <dnemergu@nrao.edu>
Date: Fri, 22 Sep 2023 11:20:15 -0400
Subject: [PATCH] Changing ingest_obs workflow to rename directories when
 starting the workflow and to indicate success/fail status

---
 ...9416c40ca8_ingest_obs_workflow_renaming.py | 60 +++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 shared/workspaces/alembic/versions/569416c40ca8_ingest_obs_workflow_renaming.py

diff --git a/shared/workspaces/alembic/versions/569416c40ca8_ingest_obs_workflow_renaming.py b/shared/workspaces/alembic/versions/569416c40ca8_ingest_obs_workflow_renaming.py
new file mode 100644
index 000000000..fd104d84d
--- /dev/null
+++ b/shared/workspaces/alembic/versions/569416c40ca8_ingest_obs_workflow_renaming.py
@@ -0,0 +1,60 @@
+"""ingest obs workflow renaming
+
+Revision ID: 569416c40ca8
+Revises: 08090cb7acc4
+Create Date: 2023-09-20 09:34:23.628834
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = '569416c40ca8'
+down_revision = '08090cb7acc4'
+branch_labels = None
+depends_on = None
+
+old_ingest_obs_sh = """#!/bin/sh
+set -o errexit
+
+./ingest_envoy --observation $1 $2
+
+"""
+
+# Workflow will rename the directory to indicate the ingestion status
+new_ingest_obs_sh = """#!/bin/sh
+set -o errexit
+
+running=${2//ready/running}
+ingested=${2//ready/ingested}
+failed=${2//ready/failed}
+
+mv $2 $running
+
+./ingest_envoy --observation $1 $running
+
+status=$?
+[ $status -eq 0 ] && mv $running $ingested || mv $running $failed
+
+"""
+
+
+def upgrade():
+    op.execute(
+        f"""
+        UPDATE workflow_templates
+        SET content=E'{new_ingest_obs_sh}'
+        WHERE filename='ingest_obs.sh'
+        """
+    )
+
+
+def downgrade():
+    op.execute(
+        f"""
+        UPDATE workflow_templates
+        SET content=E'{old_ingest_obs_sh}'
+        WHERE filename='ingest_obs.sh'
+        """
+    )
-- 
GitLab