I have a workflow that has a python code less than 100 lines run in Designer in about 8 minutes. When running from Gallery it completes in 4hrs. Is there any reason why this is happening? and/or how to resolve it?
##Python code below##
from ayx import Alteryx
import pandas as pd
import os
import subprocess
from datetime import datetime, timedelta
# Read the input data from Alteryx
df = Alteryx.read("#1")
# Path to the 7-Zip executable
seven_zip_path = r'C:\Program Files\7-Zip\7z.exe'
# Path to save the batch script
batch_script_path = 'CSD-MFT BATCH FILE.bat'
# Open the batch script file for writing
with open(batch_script_path, 'w') as bat_file:
# Write the initial batch script setup
bat_file.write('@echo off\n')
bat_file.write('setlocal EnableDelayedExpansion\n\n')
for index, row in df.iterrows():
# Extract details from each row
source_file_path = row['FullPath']
file_name = row['Output File Name']
password = row['Password']
mft_folder = row['MFT Folder ']
extension = row['Extension']
# Handle different extensions
if extension == '.csv':
# Handle CSV files (no compression)
target_file_path = os.path.join(mft_folder, file_name)
bat_file.write(f'echo Copying {source_file_path} to {target_file_path}...\n')
bat_file.write(f'copy "{source_file_path}" "{target_file_path}"\n')
elif extension == '.zip':
# Handle ZIP files
target_zip_file_path = os.path.join(mft_folder, file_name.replace('.csv', '.zip'))
if pd.notna(password) and password.strip():
bat_file.write(f'echo Zipping {source_file_path} to {target_zip_file_path} with password...\n')
bat_file.write(f'"{seven_zip_path}" a -tzip -p{password} "{target_zip_file_path}" "{source_file_path}"\n')
else:
bat_file.write(f'echo Zipping {source_file_path} to {target_zip_file_path} without password...\n')
bat_file.write(f'"{seven_zip_path}" a -tzip "{target_zip_file_path}" "{source_file_path}"\n')
elif extension == '.gzip':
target_gzip_file_path = os.path.join(mft_folder, file_name.replace('.csv', '.gz'))
bat_file.write(f'echo Compressing {source_file_path} to {target_gzip_file_path} using 7-Zip...\n')
bat_file.write(f'"{seven_zip_path}" a -tgzip "{target_gzip_file_path}" "{source_file_path}"\n')
else:
print(f"Unsupported file extension: {extension}")
# Finalize the batch script
bat_file.write('\necho Processing complete.\n')
bat_file.write('pause\n')
print(f"Batch script created at {batch_script_path}")
# Execute the batch script
try:
subprocess.run([batch_script_path], check=True, shell=True)
print("Batch script executed successfully.")
except subprocess.CalledProcessError as e:
print(f"An error occurred while executing the batch script: {e}")
# Write output to Alteryx
Alteryx.write(df, 1)
Hi @Peter_Guirguis ,
It looks ok to me!
A few things for you to do or verify
Let me know if any of these work.
Best,
Fernando Vizcaino
Thanks Fernando, I was already testing on Server's Designer and getting the same results, I will try the timestamps idea that's very good idea