Thanks for the help. I managed to slog though most of my problems, and I’m left with two remaining.
1: rescheduling the timer results in the called function being out of context.
2: scheduling four timers results in a threading problem.
hvacGroupName.forEach(v => { logger.warn("member of hvac zone: " + v);
var zoneGroup = items.getItem(v); logger.warn(zoneGroup.name);
zoneGroup.descendents.forEach(control => { //logger.warn(zoneGroup.name + " controls: " + control.name);
if (control.name.startsWith("ControlsHeatsetpoint")){
// for testing initial case
cache.remove(control.name + "Timer");
logger.warn("control.name: " + control.name);
var myTimer = cache.get(control.name + "Timer");
if(myTimer == null){ //logger.warn("initial creation of timer");
myTimer = setTimeout(
myExpire,
time.toZDT(triggeringItem).getMillisFromNow(),
control.name); //logger.warn("initial creation of timer2");
cache.put(control.name + "Timer", myTimer); //logger.warn("initial creation of timer3");
} else { logger.warn("rescheduling timer for " + ts2);
myTimer.reschedule(time.toZDT(triggeringItem).getMillisFromNow()); logger.warn("rescheduled timer");
}
}
});
});
myTimer.reschedule(time.toZDT(triggeringItem));
results:
2022-09-02 13:05:01.930 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job '<unknown>' failed and stopped
java.lang.IllegalStateException: The Context is already closed.
at com.oracle.truffle.polyglot.PolyglotEngineException.illegalState(PolyglotEngineException.java:129) ~[?:?]
at com.oracle.truffle.polyglot.PolyglotContextImpl.checkClosed(PolyglotContextImpl.java:1025) ~[?:?]
at com.oracle.truffle.polyglot.PolyglotContextImpl.enterThreadChanged(PolyglotContextImpl.java:608) ~[?:?]
...
Surprisingly, I can’t reschedule with another millisecond offset, I have to use ZDT instead
myTimer.reschedule(time.toZDT(triggeringItem).getMillisFromNow());
2022-09-02 13:07:01.213 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '386125b78d' failed: org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (reschedule) on org.openhab.core.model.script.internal.actions.TimerImpl@1b81a41c failed due to: Cannot convert '720.0'(language: Java, type: java.lang.Double) to Java type 'java.time.ZonedDateTime': Unsupported target type.
I have the problem when I am trying to create four timers. This portion of code is in a loop, and one of my test cases requires four timers to be created, and I am getting the single thread allowed error. I read about this, and am currently searching to find that thread again.
Maybe there’s a better way? I would sure like to use the expire approach, but I can’t set the expire timeout value in a rule.
I used a hashmap of timers in my old Rules DSL, would that be a better approach here?