Project Library Script Scope Issues in Gateway Scheduled Script

I'm getting a repeated error in a gateway scheduled script that doesn't make sense to me. Starting over the weekend, an hourly scheduled script just stopped finding the project library script and errors every time it runs.

Here are some screenshots and the relevant callstack trace:

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 6, in onScheduledEvent NameError: global name 'OEE_Metrics' is not defined
at org.python.core.Py.NameError(
at org.python.core.PyFrame.getglobal(
at org.python.pycode._pyx3369.onScheduledEvent$1(:6)
at org.python.pycode._pyx3369.call_function()
at org.python.core.PyFunction.function___call__(
at org.python.core.PyFunction.__call__(
at org.python.core.PyFunction.__call__(
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(
at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(
at com.inductiveautomation.ignition.common.script.ScheduledScriptManager$
at com.inductiveautomation.ignition.common.util.ExecutionQueue$
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$ Source)
at java.base/ Source)
Caused by: org.python.core.PyException: NameError: global name 'OEE_Metrics' is not defined
... 19 common frames omitted

I'm not sure why this is happening, because I think the project library scripts should be in scope automatically. It's also weird because it was working just fine last week, and I can't find any change made that could've caused this issue.

Any ideas on how to fix this?
Should I just try a gateway restart (undesirable on this production gateway)?
Is this a bug in Ignition?

Ignition v8.1.27 (b2023042509)

That usually means someone edited that script and introduced a syntax error. Or some other error is occurring at the top level, prevent it from being imported. Look in your gateway logs. Try making a trivial change in that script, and saving the project. If there's a problem with its automatic import, it should show up in the gateway log shortly after.

(Adding or removing a blank line at the bottom is a pretty safe trivial change.)

1 Like

Hmmm. Well apparently that worked. If I had to guess, I'd say that the script restart is what fixed it.

I'll keep that tip about syntax errors in mind though, I've definitely done that before.

Thanks for the help!

Any chance there's something that script does during initialization that wasn't working the last time scripting restarted? If so, you should move that initialization fragment into an asynchronous task that can report failures separately, and be retried as needed.

It has two import statements and function definitions. No code besides that. I just realized that I'm not even using those imports anywhere, so that shouldn't matter.

import sys
import java.lang.Exception

After some digging, it looks like a duplicate database entry from the store and forward system was the first of a couple failures, including this issue and a failed gateway backup. I don't suspect this will be a recurring problem, but we're still looking into it...