Gateway event script sometimes fails to execute a function

A gateway event script -> timer does not require the project name either. Those scripts are project based so the project name is not required.

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.

1 Like

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.)

4 Likes

I’ve got to agree with this. From a users perspective, runNamedQuery() is unnecessarily quirky.

Someone has posted this in ideas for anyone interested in seeing this modified.
https://inductiveautomation.canny.io/ignition-features-and-ideas/p/simplify-systemdbrunnamedquery-gatewayproject-scope

Unfortunately, I still can’t log into the ideas site. It’s been quite a while since I was notified that ticket was in progress… /:

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.

It is not clear in this post if you are really using a Tag Change Script in a project’s Gateway Event scripts, or if you are using a ValueChange or other event directly on a tag. The former are in a project and have access to that project’s script modules (and any inherited scripts in v8). The latter are not in a project and have access only to shared scripts (v7.9) or to the script modules in the Global Scripting Project (v8).

1 Like

About to start testing them again and watching closely to the data this time.

I’m super confused at this point. The only thing that might make sense is the PCs are running different versions of Java…

Try copying the script into the script console, make it a function and then call it at the bottom of the console.
This is an easy way to see any errors that pop up in both the main script and the sub function call.
Something like:

testTagCall(initialChange):
    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)
                return var_Furnace,id1,id2
print testTagCall(0)

No errors popped up. Would this function execute? My Gateway logger doesn't show that function executing (I use an info logger inside the function).

Return/Print other variables in the call

return PairID,id1,id2

Or you can just print them right inline

if tempReachedAched == 1:
    pairID = system.tag.read(;somePath').value
    print pairID

etc.

So the attached picture executes and returns what I expect from the function and also updates the tags in the program. However, the function itself doesn’t write anything to the gateway logger.

def soakPointReached1(furnaceName, uid1, uid2):
    dewaxLogger = system.util.getLogger("Dewax")
    dewaxLogger.info('Executing func soakPointReached1')
    return 3

Thoughts?

Sidenote: I figured out why my second picture in this thread wasn’t executing. The function being called was looking at a local directory to delete some CSV file. Obviously this directory doesn’t exist on the gateway (at least I hope it doesnt)

Sidenote2: My original problem I’ve been unable to replicate. We ran 8 furnaces back to back and all performed as expected. So it’s looking more and more like user error on my part.

I’m curious to know if you have the dedicated thread option turned on for this tag change event script?

I’m sure that certain people whom have already posted on this thread have some good insites to offer on the the impact of doing relatively long processes inside tag change scripts (Database Updates/File System Modifications) could have on your system if you are using shared threading.

Bill

This is version 7.9 and I don’t see a threading option for gateway tag change scripts.

I haven’t seen this issue since the first time it happened so either it’s a very rare event or it’s not a real problem… will investigate 1 more week and then probably close this thread.

I’m curious to know if you have the dedicated thread option turned on for this tag change event script?

This option is for Timer scripts.