Skip to content
Snippets Groups Projects
ff62e9b2399f_carta_workflow_alterations.py 2.33 KiB
"""carta workflow alterations

Revision ID: ff62e9b2399f
Revises: 18521b94d2f8
Create Date: 2021-08-13 14:34:42.139098

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "ff62e9b2399f"
down_revision = "18521b94d2f8"
branch_labels = None
depends_on = None


script = """#!/bin/sh
set -o errexit

export HOME=$TMPDIR

{{#need_data}}
./framework.sh -r .
cd rawdata/
../productfetcher {{product_locator}} &
.{{/need_data}}./carta_envoy {{#need_data}}--parallel{{/need_data}} -d $1 -n $2 -wf $3 -r $4 {{#need_data}}&{{/need_data}}

"""

condor = """executable = carta.sh
arguments = {{source_dir}} {{user_email}} {{request_id}} {{notify_ready}}

output = carta.out
error = carta.err
log = condor.log

SBIN_PATH = /lustre/aoc/cluster/pipeline/$ENV(CAPO_PROFILE)/workspaces/sbin
should_transfer_files = yes
transfer_input_files = $(SBIN_PATH)/pycapo, $(SBIN_PATH)/framework.sh, $(SBIN_PATH)/productfetcher, $(SBIN_PATH)/carta_envoy
{{#need_data}}transfer_output_files = rawdata{{/need_data}}

request_memory = {{ramInGb}}
getenv = True
environment = "CAPO_PATH=/home/casa/capo"
requirements = HasLustre == True

queue

"""

old_script = """#!/bin/sh
set -o errexit

export HOME=$TMPDIR

cd $1
{{#needData}}
./productfectcher $2 &
{{/needData}}
./carta_envoy -w $1 &

"""

old_condor = """executable = carta.sh
arguments = {{source_directory}} {{image_list}}

output = carta.out
error = carta.err
log = condor.log

SBIN_PATH = /lustre/aoc/cluster/pipeline/$ENV(CAPO_PROFILE)/workspaces/sbin
should_transfer_files = yes
transfer_input_files = $(SBIN_PATH)/pycapo, $(SBIN_PATH)/carta_envoy

request_memory = {{ramInGb}}
getenv = True
environment = "CAPO_PATH=/home/casa/capo"
requirements = HasLustre == True

queue

"""


def upgrade():
    op.execute(
        f"""
        UPDATE workflow_templates 
        SET content=E'{script}' WHERE filename='carta.sh'
        """
    )
    op.execute(
        f"""
        UPDATE workflow_templates
        SET content=E'{condor}' WHERE filename='carta.condor'
        """
    )


def downgrade():
    op.execute(
        f"""
        UPDATE workflow_templates 
        SET content=E'{old_script}' WHERE filename='carta.sh'
        """
    )
    op.execute(
        f"""
            UPDATE workflow_templates
            SET content=E'{old_condor}' WHERE filename='carta.condor'
            """
    )