[JSR223] Jython - how do created rules get deleted?

Hi,

I had some problems I could not pin down properly.
It seemed, that rules I created for jrs223 did get executed multiple times when I do some changes in the file because the “old” rule did not get removed. Could this be true?

This is how I added my rules:

def getRules():
    return RuleSet([

        cSimplePresence(  "Bad_MuSe6_Alarm_Anz",                "Anwesend_Bad"),
        cSimplePresence(  "Kuche_MuSe6_Alarm_Anz",              "Anwesend_Kueche"),

        cSimplePresence(  "Schlafzimmer_Fenster_Alarm_Anz",     "Anwesend_Schlafzimmer"),

        cSimplePresence(  "Flur_Wohnungstuere_Alarm_Anz",       "Anwesend_Flur"),
        cSimplePresence(  "Wohnzimmer_Balkontuere_Alarm_Anz",   "Anwesend_Wohnzimmer"),
    ])

It shouldn’t be true. You could create a unique value (like a UUID) for each rule instance and log it when the rule is invoked. That would show you if the same rule instance is being invoked multiple times or not.

Good idea - I’ll maybe put this in a base class.
Anyway I did restart my openhab instance and the problems are gone.
Thread can be closed.

I have observed the same behaviour and can reproduce it with the following rule:

class TestRule(Rule):

    def getEventTrigger(self):
        return [
            TimerTrigger("0 * * * * ?")
        ]

    def execute(self, event):
        oh.logDebug("TestRule", "event received: " + str(event))

def getRules():
    return RuleSet([
        TestRule()
    ])

The first log message is:

2016-10-08 12:10:00.014 [DEBUG] [.openhab.model.jsr223.TestRule] - event received: Event [triggerType=TIMER, item=null, oldState=null, newState=null, command=null]

After that I have added a space in the log statement between “event” and “received” without stopping openHAB. The rule is reloaded:

2016-10-08 12:10:05.127 [INFO ] [o.c.j.i.e.scriptmanager.Script] - Loading Script test.py
2016-10-08 12:10:05.130 [INFO ] [o.c.j.i.e.scriptmanager.Script] - EngineName: jython
2016-10-08 12:10:05.150 [INFO ] [o.o.c.j.i.e.s.ScriptManager   ] - Engine found for File: test.py

After that I get two log messages at the same time:

2016-10-08 12:11:00.005 [DEBUG] [.openhab.model.jsr223.TestRule] - event  received: Event [triggerType=TIMER, item=null, oldState=null, newState=null, command=null]
2016-10-08 12:11:00.007 [DEBUG] [.openhab.model.jsr223.TestRule] - event received: Event [triggerType=TIMER, item=null, oldState=null, newState=null, command=null]

As one can see from the log, the previous rule is not deleted and is also executed. After a restart, the rule is only executed once.

Is this the desired behaviour?

I have found the root cause of this problem. The behaviour depends on the editor used.

The problem seems to stem from ScriptUpdateWatcher in org.openhab.core.jsr223. It uses java.nio.file.Watch*, which reports whether a file is created, deleted or modified. Depending on the editor, it may report “created” for modified files.

Thanks for the analysis. I’ll just delete the corresponding files first before coping.