B4J Question Web server issues when started from scheduled tasks

PSEAD

Member
Licensed User
Longtime User
I have a webapp that runs fine when launched from a command window, but bombs when launched from scheduled tasks. Everything works in debug and release mode under the ide as well.
The server initiates an API request for each chess player (from Lichess) and receives a json string which is used to populate a table. This is presented in a simple datatable which provides a ranking list.
I have sent the logs to a file and the very first request seems to work fine (first player in green text), but from the second player the request kicks out the message :

2020-06-24 15:12:55
{"id":"banelevich","username":"Banelevich","online":false,"perfs":{"chess960":{"games":101,"rating":2005,"rd":62,"prog":65},"antichess":{"games":1,"rating":1475,"rd":345,"prog":0,"prov":true},"puzzle":{"games":206,"rating":2185,"rd":74,"prog":5},"racingKings":{"games":5,"rating":1656,"rd":178,"prog":0,"prov":true},"ultraBullet":{"games":449,"rating":2009,"rd":49,"prog":-34},"blitz":{"games":11533,"rating":2475,"rd":45,"prog":13},"crazyhouse":{"games":8,"rating":1505,"rd":148,"prog":0,"prov":true},"bullet":{"games":3190,"rating":2532,"rd":45,"prog":14},"correspondence":{"games":0,"rating":1500,"rd":350,"prog":0,"prov":true},"classical":{"games":6,"rating":1954,"rd":238,"prog":0,"prov":true},"rapid":{"games":81,"rating":2134,"rd":68,"prog":22}},"createdAt":1491742692902,"profile":{"country":"ZA","firstName":"Banele Fortune ","lastName":"Mhango","fideRating":2117,"links":"https://kingsof64squares.webnode.com/"},"seenAt":1592972532831,"patron":true,"playTime":{"total":4136716,"tv":82386},"language":"en-GB","title":"FM","url":"https://lichess.org/@/Banelevich","nbFollowing":140,"nbFollowers":721,"completionRate":100,"count":{"all":15521,"rated":15379,"ai":0,"draw":1308,"drawH":1308,"loss":5296,"lossH":5296,"win":8917,"winH":8917,"bookmark":26,"playing":0,"import":0,"me":0}}
Sleeping

main._appstart (java line: 85)
java.lang.RuntimeException: java.io.FileNotFoundException: C:\Users\ADMINI~1\AppData\Local\Temp\2 (Access is denied)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
at anywheresoftware.b4a.BA$3.run(BA.java:247)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153)
at b4j.example.main._appstart(main.java:85)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.main(main.java:28)


I would assume permission issues and have tried various options without any difference. Also it would not explain why the first one is successful.
I have also checked "C:\Users\Administrator\AppData\Local\Temp\2" and I see that every json reply has created a new file (is this normal?). The web service part continues serving web pages without updating.

It is currently running fine, but under a cmd window, which is not ideal. I need the app to start automatically if the server reboots. Any ideas would be appreciated.
 

DonManfred

Expert
Licensed User
Longtime User
but bombs when launched from scheduled tasks
based on the path you need to use the ADMIN Account as a normal user does not have rights to access ADMINs Folders.
 
Upvote 0

PSEAD

Member
Licensed User
Longtime User
based on the path you need to use the ADMIN Account as a normal user does not have rights to access ADMINs Folders.
There is only the one account on the VPS which is the admin account, and the first response works correctly, so that makes me think it is something else.
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
Don't run it as a scheduled task you need to run it as a service.
Don't run it using an Administrator user account. Create a user and give specific permissions to access the folders required.
Any program can be wrapped as a service. I use NSSM: https://nssm.cc/ but other service managers are available.
 
Upvote 0

PSEAD

Member
Licensed User
Longtime User
based on the path you need to use the ADMIN Account as a normal user does not have rights to access ADMINs Folders.
I did a test now clearing the temp folder and it does seem to be a permissions problem after all. The first message comes in, gets written to the database etc. so everything looks correct, but it does not write the json response to the temp folder. I have checked and it is running under the administrator account.
I wonder why it needs the temp folder in the first place?
 
Upvote 0

PSEAD

Member
Licensed User
Longtime User
Don't run it as a scheduled task you need to run it as a service.
Don't run it using an Administrator user account. Create a user and give specific permissions to access the folders required.
Any program can be wrapped as a service. I use NSSM: https://nssm.cc/ but other service managers are available.
Thanks. Will try this. I thought of creating another account.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I have a webapp that runs fine when launched from a command window, but bombs when launched from scheduled tasks. Everything works in debug and release mode under the ide as well.
How does your program stop? From the green log, it looks like the program goes to sleep and does not terminate. Since you are scheduling this to run periodically, it needs to end once it is done processing, otherwise it will block the resources that the subsequent runs need.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
i agree with most people here about making it a service and creating a special user for it.

I had the same issue a month ago, i did not understand why it was trying to save something to that specific folder to solve it i created the folder in C:\Server and in the bat file that was running i changed the working directory before running the jar.

Before that solution i had the app in a E:\ drive within several folders deep and was throwing that issue, i dont know what fixed it, to be in the same drive, to be near root or it was just pure luck.
 
Upvote 0
Top