Web server and new glasses

Some years ago I wrote my first Node.js Hapi.js program. Now it was time to write the second, or rather extend the first with a new function. First I upgraded  Node and Hapi from releases 0.x.x something to node vs  8.4.0 and Hapi vs 16.5.2, it looked like a giant leap and I expected to rewrite all from scratch, but only a few simple adjustment was needed.
The first version run a Data Warehouse job in the background and at the end responded if it was a success or not. That was fine until some long running made the HTTP interface time out. After many futile attempts to fix the timeout, I called Andreas he told ‘you don’t do it that way, create one function that starts the job and immediately return the pid of the submitted job, and another function that replies if the pid is active or not. I should have figured out that myself, but I didn’t.
Anyway that should be simple and it actually was except for one detail, I have new glasses, text is a bit blurred with the new lenses.

var foo = spawn("/bin/ps", [' -p ' + pid]. {shell: true});
The invalid dot magnified, should be a comma.
I had by mistake written a . (dot) instead of a , (comma), but I did not see the dot to me it looked the same as the comma it should be. Spending an entire day on google trying to figure out what the problem was, I finally rewrote the spawn statement and it worked just fine. Sometimes programming is so frustrating, simple things can take forever.
Now I will rewrite this simple web server into a proper REST server. This should be easy, my program is more or less a REST server as it is, I just have to tweak the code a bit.
But as usual I’m confused with the never ending list of ever growing Node js frameworks. I am thinking adding TrailsJs to Hapi.js just for the hell of it. I have absolutely no clue what the implications of that is.

The new “PID active” function:

It remains to be seen if I have to set the spawned process as detached or not. According to the documentation ‘detached’ is for Windows only.

No comments:

Post a Comment