Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

JSR223 scripts loaded before ScriptExtensionProviders are initialized #4808

Closed
wborn opened this issue Dec 23, 2017 · 4 comments
Closed

JSR223 scripts loaded before ScriptExtensionProviders are initialized #4808

wborn opened this issue Dec 23, 2017 · 4 comments

Comments

@wborn
Copy link
Contributor

wborn commented Dec 23, 2017

I'm using the JSR223 scripting engine with some Groovy scripts to update the state of some items with Thing status and firmware information. That all works well. However when I start openHAB 2.2.0 the scripts are loaded before the DefaultScriptScopeProvider is fully initialized.

This results in the following error:

21:23:58.192 [ERROR] [ript.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/test.groovy': javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: things for class: Script1

When the runtime has fully started and I save the same script the error does not occur.

@smerschjohann
Copy link
Contributor

As we don't know when the whole platform is initialized, the ScriptFileWatcher currently waits for 25 seconds before importing the scripts located at the jsr223 directory.

It seems this delay is not enough in your case. It might be a good idea to make this delay configurable.

Another option would be the following: You define a 000_burntime.groovy which just "burns" additional time by sleeping for a specific amount of time. As this file will be always loaded first and all scripts are imported sequentially, this would solve your issue.

@wborn
Copy link
Contributor Author

wborn commented Dec 24, 2017

It may take my RPi3 up to 10 minutes to get everything fully started so I guess the 25 seconds are a bit short in that case.

I'll try the workaround but I put in this issue so everyone does not have to resort to manually applying such workarounds. :-)

@vbier
Copy link

vbier commented Jan 10, 2018

This is a duplicate of #4324. And it is a really annoying problem, as you have to add a rule with a system startup trigger that touches the groovy file to get it working.
Unfortunately, the rule does not only run at system startup (or openHAB restarts itself from time to time), as I can see that my rules are discarded and added again every now and then.

@wborn
Copy link
Contributor Author

wborn commented Jan 10, 2018

Since it is indeed a duplicate I'll close this issue. I've solved this issue (and others) for myself with hardware by migrating from a RPi3 to an Intel NUC.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants