From 8cb2da1112181e32ea0190e42cff590e7ca1f928 Mon Sep 17 00:00:00 2001 From: Nathan Bockisch <nbockisc@nrao.edu> Date: Tue, 4 Apr 2023 13:54:11 -0400 Subject: [PATCH] Fixed the mustache syntax of the pims email template --- .../0dc708eecbc6_fix_pims_split_templates.py | 181 ++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 shared/workspaces/alembic/versions/0dc708eecbc6_fix_pims_split_templates.py diff --git a/shared/workspaces/alembic/versions/0dc708eecbc6_fix_pims_split_templates.py b/shared/workspaces/alembic/versions/0dc708eecbc6_fix_pims_split_templates.py new file mode 100644 index 000000000..3d38d22f6 --- /dev/null +++ b/shared/workspaces/alembic/versions/0dc708eecbc6_fix_pims_split_templates.py @@ -0,0 +1,181 @@ +"""fix pims split templates + +Revision ID: 0dc708eecbc6 +Revises: 7018d6a27433 +Create Date: 2023-04-04 10:24:33.728436 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '0dc708eecbc6' +down_revision = '7018d6a27433' +branch_labels = None +depends_on = None + +old_pims_notification = """ +Subject: PIMS Split Workflow Finished + +Dear DA, + +{{status}} + +Calibration: {{calibration}} +CASA from: {{casa_path}} +Restore path: {{restore_path}} +Lustre processing area: {{lustre_dir}} +Cache directory: {{cache_dir}} + +{{#num_products.length}} +SE Coarse Cube and Continuum images per tile in the database: +{{#num_products}} +Tile: {{tile_name}}, CC: {{num_coarse_cube}}, SE: {{num_continuum}} +{{/num_products}} +{{/num_products.length}} + +Failed Splits/Total Splits: {{num_failed_splits}}/{{num_splits}} +{{#failed_splits.length}} +Failed splits: +{{#failed_splits}} +{{.}} +{{/failed_splits}} +{{/failed_splits.length}} + +Best regards, +NRAO Workspaces +""" + + +new_pims_notification = b"""Subject: PIMS Split Workflow Finished + +Dear DA, + +{{status}} + +Calibration: {{calibration}} +CASA from: {{casa_path}} +Restore path: {{restore_path}} +Lustre processing area: {{lustre_dir}} +Cache directory: {{cache_dir}} + +SE Coarse Cube and Continuum images per tile in the database: +{{#num_products}} +- Tile: {{tile_name}}, CC: {{num_coarse_cube}}, SE: {{num_continuum}} +{{/num_products}} + +Failed Splits ({{num_failed_splits}}/{{num_splits}}): +{{#failed_splits}} +- {{.}} +{{/failed_splits}} + +Best regards, +NRAO Workspaces +""" + +old_split_sh = b"""#!/bin/sh +export HOME=$TMPDIR +TILE=$(echo $1 | cut -d "/" -f 1) +PHCENTER=$(echo $1 | cut -d "/" -f 2) + +# Get the measurement set path +{{^existing_restore}} +MS={{data_location}}/working/*.ms +{{/existing_restore}} +{{#existing_restore}} +MS={{existing_restore}} +{{/existing_restore}} + +# Link it in the splits rawdata +ln -s $MS rawdata/ + +# Run CASA +./casa_envoy --split metadata.json PPR.xml + +# Populate cache +./pimscache cp -c {{vlass_product}} -t $TILE -p $PHCENTER working/*_split.ms + +touch {{data_location}}/failed_splits.txt + +# If pimscache call failed, output the failed split to a file for pims_analyzer +if [[ $? -ne 0 ]] ; then + echo "${TILE}.${PHCENTER}" >> {{data_location}}/failed_splits.txt +fi + +# Run quicklook if second parameter was given +if ! [[ -z "$2" ]]; then + curl --request PUT --header "Content-Length: 0" $2 +fi +""" + +new_split_sh = b"""#!/bin/sh +export HOME=$TMPDIR +TILE=$(echo $1 | cut -d "/" -f 1) +PHCENTER=$(echo $1 | cut -d "/" -f 2) + +# Get the measurement set path +{{^existing_restore}} +MS={{data_location}}/working/*.ms +{{/existing_restore}} +{{#existing_restore}} +MS={{existing_restore}} +{{/existing_restore}} + +# Link it in the splits rawdata +ln -s $MS rawdata/ + +# failed_splits.txt needs to be present even if its empty for pims_analyzer +touch {{data_location}}/failed_splits.txt + +# Run CASA +./casa_envoy --split metadata.json PPR.xml + +# Populate cache +./pimscache cp -c {{vlass_product}} -t $TILE -p $PHCENTER working/*_split.ms + +# If pimscache call failed, output the failed split to a file for pims_analyzer +if [[ $? -ne 0 ]] ; then + echo "${TILE}.${PHCENTER}" >> {{data_location}}/failed_splits.txt +fi + +# Run quicklook if second parameter was given +if ! [[ -z "$2" ]]; then + curl --request PUT --header "Content-Length: 0" $2 +fi +""" + +def upgrade(): + conn = op.get_bind() + conn.execute( + f""" + UPDATE workflow_templates + SET content=%s WHERE filename='split.sh' + """, + new_split_sh + ) + conn.execute( + f""" + UPDATE notification_templates + SET template=%s WHERE name='pims_notification' + """, + new_pims_notification + ) + + +def downgrade(): + conn = op.get_bind() + conn.execute( + f""" + UPDATE workflow_templates + SET content=%s WHERE filename='split.sh' + """, + old_split_sh + ) + conn.execute( + f""" + UPDATE notification_templates + SET template=%s WHERE name='pims_notification' + """, + old_pims_notification + ) -- GitLab