I'm trying to build a functional interface to a basic mongodb database, and boy is it not falling into place easily. I have already given up on building a general gateway script executor so I can call normal mongodb methods from within project scripts (since all the mongo call have to be done at the gateway level), and now I am just building mapped methods to pass through to the gateway.
I have a project script that looks like this:
def find(db, col, filt, projection=None, sort=None, collation=None, limit=10, skip=0):
payload = {"db": db, "collection": col, "filter": filt, "projection": projection, "sort": sort, "collation": collation, "limit": limit, "skip": skip}
print("find", payload)
return system.util.sendRequest("myProject", "mongo_find", payload=payload)
with a gateway script ("mongo_find"):
def handleMessage(payload):
db = payload.get("db", "mongodb")
col = payload.get("collection", "test")
filt = payload.get("filter", {})
proj = payload.get("projection", {})
sort = payload.get("sort", {})
colla = payload.get("collation", {})
limit = payload.get("limit", 10)
skip = payload.get("skip", 0)
return system.mongodb.find(db, col, filt, projection=proj, sort=sort, collation=colla, limit=limit, skip=skip)
The idea is that my project can just use my MyMongo.find()
call and not worry about sending / formatting the gateway message.
However, it is terribly unstable. The only reason I am still trying to make this work is that I had it working briefly in some half-baked script capacity, but as it is above, I am constantly met with this error when I invoke the following in the script console (and I can't even tell if it is my code or if there is something gummed up in the Gateway itself):
MyMongo.find("mongodb", "test", {"testing": True})
16:51:02.491 [GatewayConnection-1] WARN com.inductiveautomation.ignition.client.gateway_interface.GatewayConnectionManager - Listener [com.inductiveautomation.ignition.client.util.gui.progress.ClientProgressManager$1@359d5753] threw uncaught error on push notification.
java.lang.NullPointerException: null
at com.inductiveautomation.ignition.client.util.gui.progress.ClientProgressManager.updateTask(ClientProgressManager.java:228)
at com.inductiveautomation.ignition.client.util.gui.progress.ClientProgressManager$1.receive(ClientProgressManager.java:114)
at com.inductiveautomation.ignition.client.gateway_interface.FilteredPushNotificationListener.receiveNotification(FilteredPushNotificationListener.java:43)
at com.inductiveautomation.ignition.client.gateway_interface.AbstractGatewayConnection.firePushNotification(AbstractGatewayConnection.java:1686)
at com.inductiveautomation.ignition.client.gateway_interface.AbstractGatewayConnection.lambda$receiveNotification$1(AbstractGatewayConnection.java:1453)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
16:52:02.443 [SwingWorker-pool-1-thread-7] ERROR designer.scripting.SystemUtilities - Error invoking sendRequest from client.
com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Results for asynchronous rpc call were not received within the specified amount of time [60000 ms] for task '0d67e022-b61f-4332-91f3-1fb6bc6e4f22'
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:360)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:330)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:287)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.invoke(GatewayInterface.java:967)
at com.inductiveautomation.ignition.client.script.DesignerSystemUtilities$SendRequestManager.invokeRequest(DesignerSystemUtilities.java:388)
at com.inductiveautomation.ignition.client.script.DesignerSystemUtilities.sendRequestInternal(DesignerSystemUtilities.java:217)
at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.sendRequestInternal(SystemUtilities.java:910)
at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.sendRequest(SystemUtilities.java:831)
at jdk.internal.reflect.GeneratedMethodAccessor86.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:552)
at org.python.core.PyObject.__call__(PyObject.java:400)
at org.python.pycode._pyx1527.find$1(<module:Mongo>:8)
at org.python.pycode._pyx1527.call_function(<module:Mongo>)
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
at org.python.core.PyBaseCode.call(PyBaseCode.java:158)
at org.python.core.PyFunction.__call__(PyFunction.java:437)
at org.python.pycode._pyx1526.f$0(<input>:1)
at org.python.pycode._pyx1526.call_function(<input>)
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1687)
at org.python.core.Py.exec(Py.java:1731)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:277)
at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:130)
at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:626)
at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:614)
at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.desktop/javax.swing.SwingWorker.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.util.concurrent.TimeoutException: Results for asynchronous rpc call were not received within the specified amount of time [60000 ms] for task '0d67e022-b61f-4332-91f3-1fb6bc6e4f22'
at com.inductiveautomation.ignition.client.util.gui.progress.ClientProgressManager$RunningTask.waitForResult(ClientProgressManager.java:453)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:314)
... 34 common frames omitted
I am sure there is a matching entry in the db (not that this should be erroring if there wasn't):
Honestly I am about | | this far away from giving up on the Ignition MongoDB driver entirely, I am certainly not excited about adding it to my license, and I may as well just send JSON objects to a separate server to then have it run as a mongo intermediary. Setting up that entire system and deploying it in parallel may be easier than trying to figure out where this is going wrong, unless someone has a really obvious tip for me to accept with great embarassment.
The way that this is all laid out is exceptionally annoying to debug.