Gateway Script Only at 4pm

Bad. If the gateway experiences any heavy load at 4pm, this expression can miss the event. Especially if using fixed delay. If using fixed period, and the event that normally falls a 3:59:59 is slightly delayed, this can fire twice in a row. The chance is low, so you wouldn't be likely to see either problem often, but it would happen.

I would use something like this in a project script module:

from java.util import Date
lastTrigPath = '[default]some/path/to/datetime/tag'

# Simple function to convert any timestamp to the trigger point on the same day
def truncateToTrigger(ts):
	return Date(ts.year, ts.month, ts.date, 16, 0, 0)

# Check if time to run the triggered event.  Call from timer script
def checkTrigger():
	last = system.tag.read(lastTrigPath).value
	nextTrig = truncateToTrigger(last)
	if nextTrig.time < last.time:
		nextTrig = system.date.addDays(nextTrig, 1)
	now = Date()
	if nextTrig.time <= now.time:
		system.tag.write(lastTrigPath, now)
		# Do the trigger stuff here

Call project.something.checkTrigger() from a gateway timer script of the desired precision. It will not double fire, and will always fire if the event is late. Even if it's late due to a gateway reboot.

4 Likes