Hi,
yesterday I created a scheduler rule with habapp.
The rule as it is runs one time per hour and works fine.
But in the log I found some warning that the job itself runs to long.
Here is the example:
Now my Question: Because it is only a warning, can I just use it as it is,
or is there a better way for such long running(~30s) jobs?
Is there a way to suppress this special warning? If suppressed it will not fill up my logs.
That’s a very long job! Can you break it up? Or, put it in a thread?
HABApp will be stalled for 30 seconds while executing your job, where light switches and everything else will not work for the duration of the long job.
It’s a warning because 30secs is quite a long time and if you do this 10 x at the same time HABApp will run out of threads.
It it’s only once every hour you can ignore the warning.
Do you interact with openhab from the function or is it just interacting with another system?
If it’s the latter a possible solution might be to put it in a extra script and run it with self.execute_subprocess
Yes you’re right.
In my case it is the last case. I do not interact with openhab.
I did some test to check my network connectivity.
For that I use speedtest-cli.
Before HabApp I run this as a cron job on the pi and just check log messages.
With HabApp my thougts were: Now I can do this as a job in habapp and store the results
in openhab. So I have a visualization.
You’ll get the output of the process.
Just print the results with “print” as a json and read it back in with HABApp.
That way you can still store the speed results in openHAB.
The 60s job is called correctly.
There is the correct print on the terminal.
Also the finish callback function is called(speedtest_finished). The print is also in the terminal.
But the Timestamp between both prints is 0 , so speedtest never runs.
If I run python myspeedtest.py from the terminal it works.
Isn’t it that from the every call?
I just copy it from the examples.
Actually I do not use them.
Will print them.later. actually I’m doing some Sport
Ok, that looks better.
But actually it looks that the started process did not run in the virtual enviroment of
the habapp.
There comes an error that the module speedtest is not found.
Should the subprocess automatically runs also I’m the correct venv,or did I need to install needed modules in the main is?
If i run the python script in the venv directly with python…/lib/myspeedtest.py everything works
Neither, you need to specify the proper interpreter. Use sys.executable instead of “python”.
I’ll release a new version next week or the week after which simplifies the process and module handling a lot. So if you’re patient you can just wait for the new version or you can try out the dev branch.
Hi, that’s not the problem. I could be Patience.
But for my understanding. Specifying the correct python version is not solution.
The process needs to run in the virtual environment or did I understand something wrong?
If I start thensxriot from a simpke Terminal Session with python myspeedtest.py it will also fail.
But doing a source activate in the habap dir Starts the venv. After that the same python myspeedtest.py works.
But that’s just for my knowledge.
I can wait to the next Version
before the Speedtest finished callback and before Speedtest finished main
is the print of the outputs. But there is nothing!
So it looks, but the output is not collected, or could not be printed.
Also using a relatic path in self.execute_python is not working.
I have to use the full path
c:/Development/Smarthome/dev_habapp/files/lib/myspeedtest.py
Now you just have to create a dict and use print(json.dumps((my_result_dict)) as the output in your script. Parsing in on the HABApp side is done with json.loads. Easy peasy