Aller au contenu

VTOM : Queue Python sur Linux

Si vous utilisez des scripts Python il peut être pratique de gérer leur exécution directement depuis Visual TOM. Voici un exemple de queue que vous pouvez configurer dans Visual TOM pour exécuter vos scripts Python

#!/bin/ksh

# RC GEN Redirect
if [ "${TOM_RESOURCE_EVAL:-0}" = "1" ]; then
    . "$TOM_ADMIN/tom_submit.rcgen" "$@"
    exit $?
fi

# ----------------------------------------------------- #
# 		    TOM SUBMITTER - PYTHON 		#
# ----------------------------------------------------- #

# Initialize the environment
. "$TOM_ADMIN/vtom_init.ksh"

# Check if TOM_JOB_ID is set
if [ -n "${TOM_JOB_ID:-}" ]; then
    # Display information
    . "$TOM_ADMIN/tom_submit.aff"
    echo "_______________________________________________________________________"
    date +"%A %d/%m/%Y - %H:%M:%S"
    echo " Script execution started..."
    echo "_______________________________________________________________________"
    echo " "

    # TEST Mode
    if [ "${TOM_JOB_EXEC}" = "TEST" ]; then
        echo "Job executed in TEST mode"
        ${ABM_BIN}/tsend -sT -r0 -m"Process completed (TEST mode)"
        ${ABM_BIN}/vtgestlog
        exit 0
    fi

    # Build arguments
    arg=""
    while [ $# -gt 0 ]; do
        arg="$arg \"$1\""
        shift
    done

    # Python script execution
    echo "Executing: /usr/bin/python3 \"$TOM_SCRIPT\" $arg"

    # Change directory if necessary
    cd "$(dirname "$TOM_SCRIPT")" || exit 1

    # Execute the Python script
    /usr/bin/python3 "$TOM_SCRIPT" $arg

    # Capture the return code
    RETCODE=$?

    # Display the end of execution
    echo "_______________________________________________________________________"
    date +"%A %d/%m/%Y - %H:%M:%S"
    echo "Script execution finished."
    echo " "

    # Handle the return code
    if [ "$RETCODE" -eq 0 ]; then
        echo "--> Exit [$RETCODE] therefore acknowledging"
        ${ABM_BIN}/tsend -sT -r$RETCODE -m"Process completed ($RETCODE)"
    else
        echo "--> Exit [$RETCODE] therefore no acknowledgment"
        ${ABM_BIN}/tsend -sE -r$RETCODE -m"Process error ($RETCODE)"
    fi

    # Log file handling
    [ -n "${TOM_LOG_ACTION}" ] && ${TOM_ADMIN}/gestlog
fi

exit $RETCODE
Étiquettes:

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *