if not initialChange:
var_Furnace = '1W'
tempReached = system.tag.read('somePath').value
tempReachedAck = system.tag.read('somePath').value
if tempReachedAck == 1:
pass
else:
pairID = system.tag.read('somePath).value
id1 = system.tag.read('somePath').value
id2 = system.tag.read('somePath').value
if pairID > 0:
#THIS LINE SOMETIMES RUNS
project.functions.tempReached(var_Furnace, id1, id2)
#THIS LINE ALWAYS RUNS
system.tag.write('somePath', 1)
Sometimes the second the second to last line of code doesnāt run though (it appears to not run). I am doing a few database queries and updates but nothing too intensive. I use an info logger but nothing appears on my console log.
furnaceLogger = system.util.getLogger("Furnaces")
Is there a way to log some steps taking place during that function call? What should I check in my gateway to see if that function is actually executing?
I donāt have a complete answer based on the code as I have never used Gateway Event Tag Change Scripts, but I do know that the furnaceLogger.info() will log to the Gateway Status page rather than the console log.
Iāve looked at the logs around the time I ran the last test and the function was indeed āskippedā from what I can tell. There are several furnaces. Furnace #1 ran correctly, furnace #2 skipped the function, and furnace #3 ran correctly. I know the function was āskippedā because in the function being called the first thing I do is log that I am accessing that function.
furnaceLogger.info('Executing function project.functions.tempReached(var_furnace, id1, id2)')
I then triggered the same tag manually after #1 and #3 ran and the logs show #2 correctly running.
Iāve added a return value on the function being called and write that info to a memory tag. I will try to replicate the issue again as I am currently at the customer site.
I donāt see how your project script would run. With how your code looks Iām assuming your not using 8.0. On 7.9 a project script runs for a specific project but you stated you are running this on a gateway script. A gateway script can not call a project script because it is running on the gateway and is not linked to a specific project. It would need to be a global shared script. You would need to move the script to your global shared scripts and then change your path to call the script to reflect it.
My mistake, I was grouping all the gateway stuff into one in my head.
Even though it may be able to call a project script, how are the queries set up since he said its running queries. Some places you donāt call out the project name when calling a query, others you do. Calling it from a gateway timer script it does have to be called but he should also see an error in his logs if the script is failing unless he did something in the project script to prevent it.
You would think that but I tested it before I replied because I knew I was bit by it before. If I do a simple project query that just calls a named query and leave the project out of the runNamedQuery function it works fine calling it from the script console but the gateway timer script will fail on the line that calls the project script. If I add in the project name then it will fail in the script console but the gateway timer script will run.
Yes runNamedQuery will require the project name, but runPrepQuery doesnāt.
This makes sense since runPrepQuery is a talking directly to a database where the named query is a project resource. So at the gateway level the project name makes sense here.
Have to love consistency. Personally I would prefer it if I could just put in the project name everywhere and have it run everywhere. There would be less chances of accidentally doing it the wrong way for where you call it.
Its the reason a lot of my scripts have something like this in them.
def queryScript(tBit=0):
queryPath = "query"
params = {}
if tBit:
data = system.db.runNamedQuery(queryPath,params)
else:
data = system.db.runNamedQuery("projectName",queryPath,params)
Then I can call it without anything passed across in places I need the project name passed in and I pass a 1 in when I call the script if I donāt need the project name.
runNamedQuery()'s function signature was mis-designed, and in a way that prevents it from being fixed in any backward-compatible form. The āprojectā argument should have been after path and parameters, and optional in project contexts. Iād love to see it deprecated, with the replacement as above. Shortened to .namedQuery(), perhaps. (I also think clients should be able to call Named Queries in other projects. Not currently possible, though it can be worked around with sendRequest.)
This is not true from what Iāve seen this morning. Iām still investigating the first issue I had with a gateway script but on a separate tag change gateway script the code can most definitely not call a project script.