Is it possible to set a gateway script to run at the top of every minute?

Hello, I’m trying to get a gateway script to trigger at the top of the minute, every minute; Example being it fires at 08:00:00, 08:01:00, 08:02:00. I know I can set a gateway script to run every minute, but is it possible to get it to fire at the top of every minute?

A forum search came across this post from 7 years ago: Run Gateway Script Every Minute

I mostly just want to check if anyone knows of any updated features that would work instead of doing it this way; or anyone that is currently doing it, what their thoughts are on it. Thank you!

How accurate do you need it to be? Even a cron-style interface to a thread pool executor can have lag for a task defined to start at the top of the minute. If you need fractional-second accuracy, you probably need to use a permanent sleeping background thread that computes the precise sleep time needed on each iteration.

1 Like

Within a couple seconds max, I don’t think it has to be super super precise but would prefer it just triggers a small sql script at the start of every minute for logging. It takes no time to run at all, I just want to have it run at the top of every minute

Jordan’s approach in that thread you linked to seems fine to me. I don’t believe there’s been any additions to Ignition since then that would help.

1 Like

Awesome thank you my friend!

Maybe you should just use the cron-style schedule mode of a Transaction Group in the SQL Bridge module.

1 Like

I would do it this way, depending on what is involved with the SQL end, YMMV

#Create a Gateway Timer Script, insert the code below
#Set the gateway timer script to execute every 750mS, with *dedicated* threading

#Run a script at the start of every minute
from time import localtime, strftime
curTime = strftime("%S", localtime())
print curTime

if curTime == "00":
	#At the start of every minute, run the script
	shared.Minute.Run()
1 Like

This approach isn’t as safe because it relies on your script actually executing on the 00 second of every minute. This probably happens most of the time, but may not happen all the time. You’re running on non-real-time hardware and a consumer OS in a garbage collected environment, after all…

Jordan’s works because the system would have to hang for an entire minute to skip an execution.

5 Likes