As often pointed out, using executeCommandLine alot might lead to unresponsiveness due to thread pool being exhausted. I wonder if a possible mitigation strategy is to run heavy commands in the background and use the REST API to perform a callback, typically by posting the output from the command into a string item.
Example rule:
rule "Normal verion without callback"
when
Item TestSwitch received command
then
val command = "echo Test";
val result = executeCommandLine(command)
// Do something with result
end
Callback version:
rule "Test callback"
when
Item TestSwitch received command
then
val command = "echo Test"
// Might wanna tuck this away in an item
val runWithCallbackCmd = "/etc/openhab2/scripts/runwithcallback.sh"
executeCommandLine(runWithCallbackCmd + "@@" + command + "@@" + TestString.name)
end
rule "Callback handling"
when
Item TestString received command
then
// Do something with state of TestString
end
Where runwithcallback.sh looks something like this:
#!/bin/bash
$1 | curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d @- "http://OPENHAB_IP:8080/rest/items/$2"
#END
It will obviously not make life for the server running openhab much easier (unless the command spends most of its time doing things like waiting for a server response) and you might want to have something which prevents the rule which launches the command from running again before callback (and the error handling to deal with edge cases like if no callback is made for whatever reason).
So, pattern or antipattern?