UDT failing to execute

Below is a simple version of the actual UDT, but the functionality is:

  1. During a period of time, count on certain conditions (check once per second)
  2. On the hour clock the results into a dataset and reset the count to 0

What I am observing is that the part of archiving the data and zeroing out the value happens only sometimes but other times it never occurs. So if the maximum seconds in an hour is 3600, I start to see values going to 5000 etc. because the reset is not happening.

What could be causing part of the code never to execute of execute only sometimes?

The trigger is just a second counter:

getSecond(now())

Which activates this tag change script

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):

	count = system.tag.read("[.]value").value
	updatedCount = count + 1
	system.tag.write("[.]value", updatedCount)
	
	if currentValue.value == 0 and system.date.getMinute(system.date.now()) == 0:
		history = system.tag.read("[.]history").value
		history = system.dataset.addRow(
			history,
			[system.date.now(), updatedCount]
		)
		system.tag.writeBlocking(
			["[.]history", "[.]value"],
			[history, 0]
		)

The UDT structure is like this:

image

Thanks,

Nick

Add some logging to the script execution that includes the value of the missedEvents flag. Maybe that’s happening.

Oh, also, it looks like you’re checking currentValue.value == 0 and optimistically assuming that your system never pauses for GC or something else that causes you not to catch the 0 second. Also something logging will hopefully expose.