Skip to content
Snippets Groups Projects

Fixed the mustache syntax of the pims email template

Merged Nathan Bockisch requested to merge fix-pims-templates into main
1 file
+ 181
0
Compare changes
  • Side-by-side
  • Inline
"""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
)
Loading