Timer script Status

Hi everyone, I have facing some issues with the timer script in Vision... On our side, we had a timer script for generating glass files... These files contain the produced glass file details and it is in CSV format. Sometimes it will work well, but sometimes it doesn't work... At that time we had to face some issues... We had put the script in TRY and Except function. So, weed to identify when the timer script has worked and not working. when it; 's not working we should trigger a mail... So already created a mail handler for this one and tested.. But don't know how to find if the script worked or not... I'll be given the script below...

from project.ftps import ImplicitFTPS
import ftplib
import traceback

Start_Time = system.date.now()
Start_Time_Tag = system.tag.writeBlocking("[c02cbsv3]c2TOPServer/testingTags/Gateway_Mail_Tags/Script_Start_Time", Start_Time)
logger = system.util.getLogger('CO02_snapshot')
lineSpeed = round(system.tag.read("[c02cbsv3]c2TOPServer/32_hegla/actProcessSpeed").value,2)

#if (lineSpeed>=0.5):

try :
	filedate= system.tag.read('[System]Gateway/CurrentDateTime').value
	filedate= system.date.format(filedate, 'yyyyMMddHHmmss')
	fileloc = "/DATA/CN_CO2/snapshot_files/"
	filename = filedate + "_snapshot_15s.csv"
	finalPath = fileloc + filename
	
	snapShotHead = ["WriteTime","Description","Environment","actProcessSpeed","nomProcessSpeed","rLastGAP","currentGlassId","currentBatchID","currentSourceOfLoad","currentGlassThickness","currentGlassType",
					"currentGlassColorCode","currentGlassLength","currentGlassWidth","coverName","powerSupplyId","supplyType","supply1Status","targetMaterial1ID","targetMaterial2ID","actTarget1KWH","actTarget2KWH",
					"actVoltage","spVoltage","actCurrent","actPower","spPower","actArcRate1","actArcRate2","spPvcValue","supplyMode","actMainGas1","spMainGas1","actMainGas2","spMainGas2","actMainGas3","spMainGas3",
					"actMainGas4","spMainGas4","actMainGas5","spMainGas5","trimGas1Status","trimGas2Status","trimGas3Status","trimGas4Status","trimGas5Status","trimGas6Status","trimGas7Status","trimGas8Status","trimGas9Status",
					"trimGas10Status","trimGas11Status","actTrimGas1","spTrimGas1","actTrimGas2","spTrimGas2","actTrimGas3","spTrimGas3","actTrimGas4","spTrimGas4","actTrimGas5","spTrimGas5","actTrimGas6",
					"spTrimGas6","actTrimGas7","spTrimGas7","actTrimGas8","spTrimGas8","actTrimGas9","spTrimGas9","actTrimGas10","spTrimGas10","actTrimGas11","spTrimGas11","actVacuumPressure","gasSelection","nomGasSegment", "RGAHydrogen", "RGAHelium", "RGAAtomicNitrogen", "RGAAtomicOxygen", "RGAWater", "RGANitrogen", "RGAOxygen", "RGAArgonIsotope", "RGAArgon", "RGACarbondioxide"]
	rowDatas = []
	
	for i in range(1,81):
		compRow = generalFunc.snapShotData(i,snapShotHead,filedate)
		rowDatas.append(compRow)
		
	snapShotDataset = system.dataset.toDataSet(snapShotHead,rowDatas)
	
	csvfiledata = system.dataset.toCSV(snapShotDataset)
	csvfiledata = csvfiledata.replace('"','')
	csvfiledata = csvfiledata.replace(',',';')
	csvfiledata = csvfiledata.replace('"True"', '"1"')
	csvfiledata = csvfiledata.replace('"False"', '"0"')
	system.file.writeFile(finalPath,csvfiledata)
	
	#SnapShot File Count Created in Ignition Server
	fileCreated = int(system.tag.read("[c02cbsv3]c2TOPServer/15_GatewayScript_Status/SnapshotFile_Created").value)
	fileInc = fileCreated + 1
	system.tag.write("[c02cbsv3]c2TOPServer/15_GatewayScript_Status/SnapshotFile_Created",fileInc)
	End_Time = system.date.now()
	End_Time_Tag = system.tag.writeBlocking("[c02cbsv3]c2TOPServer/testingTags/Gateway_Mail_Tags/Script_End_Time", End_Time)
	system.tag.writeBlocking("[c02cbsv3]c2TOPServer/testingTags/Gateway_Mail_Tags/SnapShot_MailTrigger", 0)
	system.tag.writeBlocking("[c02cbsv3]c2TOPServer/testingTags/Gateway_Mail_Tags/Snapshot_Script_Status",1)
#	system.tag.writeBlocking("[c02cbsv3]c2TOPServer/testingTags/Gateway_Mail_Tags/Error_File_Count",0)
#	system.util.getLogger(logger).info(str("Snapshot file created succesfully"))
	logger.info('snapshot generated')

except Exception as e :
		Nc_File = system.tag.readBlocking("[c02cbsv3]c2TOPServer/testingTags/Gateway_Mail_Tags/Error_File_Count")[0].value
		Nc_Count_inc = Nc_File + 1
		system.tag.writeBlocking("[c02cbsv3]c2TOPServer/testingTags/Gateway_Mail_Tags/Error_File_Count",Nc_Count_inc)
#		system.tag.writeBlocking("[c02cbsv3]c2TOPServer/testingTags/Gateway_Mail_Tags/SnapShot_MailTrigger", 1)
#		system.tag.writeBlocking("[c02cbsv3]c2TOPServer/testingTags/Gateway_Mail_Tags/Snapshot_Script_Status",0)
		logger.info(str("Snapshot not Created"))
#		system.util.getLogger(log_name).info(traceback.format_exc())
#	pass
		

Thanks,

Muniyandi

Few things -

  1. You say this is on a vision client timer script? I think this is more suited for a gateway script. Should a vision client have to be on and alive for this to be running every x time period? If it should, then keep it where it is, but if it should be generating these files every x time period no matter client status, it belongs on a gateway script.

  2. Since it's in vision any errors would be in the vision client logs. Once the client closes though you will no longer see them. I also don't think in general it keeps track of as many logs as the gateway does so you can lose it. With this on the gateway the logs will live longer.

  3. You're not capturing the error. You're just saying logger.info(str("Snapshot not Created")) but doesn't tell you why. Looks like someone was trying to capture the error here - system.util.getLogger(log_name).info(traceback.format_exc()) I would leave this back in (though as logger.error(traceback.format_exc()) ) and also log the str(e)as well. This will tell WHY things went wrong when they do so then you can code carve outs for how to handle those situations.

  4. Sending an email to alert devleoper/admin is a good idea on error, you can use system.net.sendEmail to do so. I would email the time and stack trace and any other relevant data like the parameters used that caused the issue in the first place. You're script isn't in a function (highly recommend doing so for multiple reasons) but it looks like youre Start_time and lineSpeed are your params so I would send those over in the email as well so you can re-test after making fixes. You would put this in the except Exception as e part of your script.