node-jt400
node-jt400 copied to clipboard
Is there a way to check if the connection is up?
I need to know if there is a method to check if the connection to DB2 is active.
Hi @eduardrock
I can't check/verify right now, but you can try pool.isClosed()
or pool.getAvailableConnectionCount()
Otherwise I'll look beter into this tomorrow :)
"the connection to DB2 doesn't respond and gets stuck" So... for example, the next pool.query command you do never responds? Maybe it would suffice to somehow set a timeout instead of checking if the connection exists? I think mine cleanly errors out when I get disconnected, but I'll have to check.
Also I can agree that I don't find those two methods mentioned previously.
Hi, sorry for the late reply.
I will try to add this over the weekend.
At this rate it might be better for you to try to attempt it yourself. Download open jt400 and add it to your class path and then connect using the AS400
https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/rzahh/javadoc/com/ibm/as400/access/AS400.html?view=embed
All classes (for i 7.2) jt400: https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/rzahh/javadoc/allclasses-noframe.html?view=embed
Then see how this project uses the npm module "java" to wrap java functions into node. Then try seeing if you can leverage one of the java commands to achieve adding whether or not the connection exists, or maybe listen to the event.
Hi @eduardrock
I understand your frustration. Its hard for us to support feature requests since my 9 to 5 job is programming what the management of TM (icelandic insurance company) wants us to develop.
This module is just a byproduct of that since at one time we needed to connect to AS400.
We try to answer every message we get but we don't have any real good time to write feature requests or go over pull requests. We do try, but there is alot of waiting. My aplogize for that.
If I find any freetime during the weekend I might be able to take a look at this but as Cody mentioned your best bet is probably to make a pull request...then the waiting time is only 2-4 weeks instead of a year (facepalm).
I am really sorry for the delay and I understand that this affects your project and work.
Sorry if this one does not fully solve your problem - I have on the other hand used the approach of performing the following query in order to verify that the connection is up and running. const result = await pool.query('values current date'); if all is good you will get the current date back if not it fails and you now the connection is down, and you can recycle the connection. @bergur If you need help with node-jt400 let me know - my main knowledge is around IBM i - Java (JT400) and node js (Typescript) - I will start out looking at the issues reported.
HJi @sorensenNiels
Thanks for your offer, that sounds really good.
Regarding checking the connection, if you have a java code that uses isConnected or isConnectionAlive to check the connection then I could implement it in this module somewhat quickly.
Hi @bergur Will do! Have been looking at the code and found that I would love to run the provided test cases - of course I could start providing the required IBM i objects but on the other hand maybe you have a savefile with the required objects :-) Can you provide? I have additional questions on the use of Java 6 and the promise package of Q.
Hi @bergur - we both have our day job and wondering if you had the SQL script for tsttbl - I'm running tests at the moment for isConnected and additional features for the IFS (get list of fields/folders in folder) finally I will be doing a PR for you.
Hi @sorensenNiels
I've added to sql to the test folder, check out a790234
It seems like you could program this on your end @edu791 by handling the errors from the connection and the queries. If the query fails then attempt to reconnect. If the reconnect fails then you know it can't be reached for whatever reason. Then code something to retry the connection until it succeeds.
I use PM2 as sort of a workaround for this. If the program crashes or errors out then it restarts the program. You can configure the restart options in PM2 to however you wish (add delays, max attempts, etc...)