Error running function from system.util.invokeAsynchronous

The end goal of this is to provide a summary of process activity after some period (overnight, weekly, etc.) so it was sending out an email for each process change. Possibly the whole thing should be re-worked to send only one email with a summary of all changes...

I got rid of the invokeAsynch. I was thinking the executeAndDistribute might need it to send multiple emails in a loop... Not sure.

The sendEmail function and new code (i.e. invokeAsynch) are within a for loop as mentioned in the post. Iterating through a SQL table for tank numbers & info.

for n in range(len(pyTankDS)):
    tankNo = pyTankDS[n][0]
	tank = 'Tank ' + tankNo

	#read relevant properties from tag path
	volume = str(round(system.tag.read('[default]Tank Status History/'+tank+'/Volume').value,1))
	
    def sendEmail(tankNo=tankNo, tank = tank, volume = volume):	
    	import system
    	recipients=["jane@test.com","jon@xyz.com"] #
	    system.report.executeAndDistribute(path="xyz", parameters = {"tankNumber":tankNo}, project="xyz", action= "email", actionSettings = {"to":recipients, "smtpServerName":"Mail Server", "from":"jon@xyz.com", "subject":tank + 'test email', "body":tank + " test " + volume})
    system.util.invokeAsynchronous(sendEmail)

print 'post-email function'
system.db.runUpdateQuery('DELETE FROM tank_fills')

Changed to:

for n in range(len(pyTankDS)):
    tankNo = pyTankDS[n][0]
	tank = 'Tank ' + tankNo

	#read relevant properties from tag path
	volume = str(round(system.tag.read('[default]Tank Status History/'+tank+'/Volume').value,1))

    recipients=["jane@test.com","jon@xyz.com"] 
    system.report.executeAndDistribute(path="xyz", parameters = {"tankNumber":tankNo}, project="xyz", action= "email", actionSettings = {"to":recipients, "smtpServerName":"Mail Server", "from":"jon@xyz.com", "subject":tank + 'test email', "body":tank + " test " + volume})

print 'post-email function'
system.db.runUpdateQuery('DELETE FROM tank_fills')

More info on this thread: