|
|
|
@ -94,37 +94,26 @@ async def create(
|
|
|
|
|
|
|
|
|
|
|
|
# Get the directory of the current file
|
|
|
|
# Get the directory of the current file
|
|
|
|
# directory_path = "../modules/plant"
|
|
|
|
# directory_path = "../modules/plant"
|
|
|
|
directory_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../modules/plant'))
|
|
|
|
directory_path = os.path.abspath(
|
|
|
|
|
|
|
|
os.path.join(os.path.dirname(__file__), "../modules/plant")
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Construct path to the script
|
|
|
|
# Construct path to the script
|
|
|
|
script_path = os.path.join(directory_path, "run.py")
|
|
|
|
script_path = os.path.join(directory_path, "run.py")
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(script_path):
|
|
|
|
|
|
|
|
logger.error(f"Script not found at path: {script_path}")
|
|
|
|
|
|
|
|
raise FileNotFoundError(f"Script not found at path: {script_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Execute script
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
process = await asyncio.create_subprocess_exec(
|
|
|
|
process = await asyncio.create_subprocess_exec(
|
|
|
|
"python",
|
|
|
|
"python", script_path, stdout=PIPE, stderr=PIPE, cwd=directory_path
|
|
|
|
script_path,
|
|
|
|
|
|
|
|
stdout=PIPE,
|
|
|
|
|
|
|
|
stderr=PIPE,
|
|
|
|
|
|
|
|
cwd=directory_path
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
stdout, stderr = await process.communicate()
|
|
|
|
stdout, stderr = await process.communicate()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Check if the script executed successfully
|
|
|
|
if process.returncode != 0:
|
|
|
|
if process.returncode != 0:
|
|
|
|
error_message = stderr.decode()
|
|
|
|
print(f"Script execution error: {stderr.decode()}")
|
|
|
|
logger.error(f"Script execution failed: {error_message}")
|
|
|
|
|
|
|
|
# Depending on your requirements, you might want to raise an exception here
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
logger.info(f"Script executed successfully: {stdout.decode()}")
|
|
|
|
print(f"Script output: {stdout.decode()}")
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
except asyncio.SubprocessError as e:
|
|
|
|
print(f"Error executing script: {e}")
|
|
|
|
logger.error(f"Failed to execute script: {e}")
|
|
|
|
|
|
|
|
raise Exception(f"Failed to execute script: {e}")
|
|
|
|
|
|
|
|
# Handle subprocess error appropriately
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return transaction_data
|
|
|
|
return transaction_data
|
|
|
|
|
|
|
|
|
|
|
|
|