Just by the label “gateway script” one would think that these scripts would run on the gateway, and they do; however they are still tied to a specific project and only run when it runs. (I am right here?) I was thinking that these should run whether a project is open or not and be available to all projects. If this isn’t the case, consider this a formal feature request. It would be helpful to sometimes run an action script regardless if a project was open or not.
Gateway scripts are always running, but you can only edit them from the project in which it was created. That one caught me, too.
The reason I brought this up, I put this script on the gateway startup script,
#This code sets any active alarms to cleared in the event of a restart
#from java.util import Date
now = Date() # creates a new date, for right now
#format the date
val = system.db.dateFormat(now, "yyyy-MM-dd HH:mm:ss")
val1 = 0
val2 = 1
system.db.runUpdateQuery("UPDATE ALERT_LOG SET CLEARED_TIMESTAMP = '%s', ACK_TIMESTAMP = '%s', ACTIVE_VALUE = %s, CLEARED_VALUE = %s WHERE cleared_timestamp is null" %(val, val, val1, val2))
It will not work, hence I assumed that the gateway scripts were project specific. This script runs fine with a button push or some other action.
Did you restart the gateway?
EDIT: Oops! Didn’t mean to sound careless on that one, just trying to cover all your bases… Also looking at your documentation I’m assuming you did…
Yep, tried it multiple times.
I am sensing some confusion. Specifically around the entire concept of what a “project” is.
The definition of “project” has been greatly expanded in Ignition from those of you who come from the FactoryPMI/FactorySQL world.
A Gateway script is part of a project, but it also always runs. This is because a project’s lifecycle is larger than a Client’s lifecycle. Some parts of a project have nothing to do with clients. Some parts of a project only live in the client. Like I said - projects have broad scope within Ignition.
A Project’s module library ([tt]app.*[/tt]) lives both in the gateway and in each client.
A Project’s gateway scripts only run in the gateway. Their lifecycle is tied to the gateway’s lifecycle. This means that the “startup script” for gateway scripts will run when the gateway starts up, not when client’s start up. It will also be run when you save the project, which “restarts” the project in the gateway.
A Project’s transaction groups only run in the gateway.
A Project’s Windows run only in the client, and will run an independent copy in each client.
Hope this clears something up.
Also - errors in gateway scripts will show up in [tt]wrapper.log[/tt] rather than in the Designer’s console.
That clears things up a little, but why does the above script not run on a gateway restart?
… because there is a bug in the gateway startup script system
Unfortunately the fix won’t make it for today’s release of 7.1.4, but:
- We’ll put up a quick beta of 7.1.5 with the bug fixed soon and…
- You can easily make your own “startup script” with a 1-minute timer script and a global flag:
first = 1
first = firstRunFlag
put your startup
firstRunFlag = 0[/code]
… because there is a bug in the gateway startup script…[/quote]
Aha! But at least the fix is something that’s coming.
Thanks for the update and the workaround.