Advanced JSR223 Jython rule

Tags: #<Tag:0x00007f616f963ef8>

I am about to get rid of my calls to Astro action from jython scripts. My need is that I can query the value of astro event times (like sunset start). But I also wants to get notified when the event actually occurs.
To fullfil the above I created a module that can publish (astro) events to different subscribers. That all seems to work great when I use a combination of a item and a ChannelEvent trigger.
I also wanted to have a trigger at a specific time each day. So I just enhanced the above with a CronTrigger option. So far everything is still great…
The problem arises when I get a CronEvent. For ChannelEvents I get an event object in the callback and thus I can nicely backtrack to the channel that caused the event to trigger, and publish a notification to all subscribers to that event. For CronTriggers this object is not set, so I don’t really know what Crontrigger that caused the event (assuming that there can be more). I tried to set the triggername, but that doesn’t seem to work.
Is there a way to get the link between the cronevent that triggered the call, so that I can backtrace. Maybe I can set some metadata that will be returned in call.

I can always create a list/dictionary of CronTriggers and then loop through this list to identify the one that triggered the event. Any better suggestions?

BTW. I am using the new Rule Binding

UPDATE: The above problem seems to be somewhat related to this post:

In my ephem_tod script which does pretty much exactly what you describe, instead of using cron triggers, I use Items.

I have a script that can be used to initialize Items with a DateTime used to boot strap the time for the Items that are replacing the cron triggers. The Astro Items of course are linked to Astro Channels. The rule then generates Timers to generate an event at the right times.

I’m not an expert but I believe the lack of which cron trigger caused the rule to trigger in event is either because of limitations in the underlying rules engine or by design.

1 Like

Thanks, I will take a deeper dive into your script. It looks interesting, be warned that I might have questions :-)…

It’s probably a philosophy question. If a cron trigger arises, it is because it is “that time” i.e. the clock is (always) the originator.

You are probably right, but when having more Cron triggers, where it matters if it is trigger 1 or trigger2, then it would be nice to know the trigger name or other metadata :grinning:
But I think Rich has pointed me in a usefull direction :grinning:

Make 2 rules each with one trigger and put the real logic in a python function that you call with an argument specifying which trigger called it.

Though by the sound of it Rich’s tod script will be a cleaner solution for what you want I think.