rkoshak / openhab-rules-tools

Library functions, classes, and examples to reuse in the development of new Rules.
Other
64 stars 23 forks source link

[timerMgr] Name timer/scheduled jobs #69

Closed florian-h05 closed 2 years ago

florian-h05 commented 2 years ago

This change names the created timers with the user provided key. Refers to https://github.com/openhab/openhab-core/pull/2911.

This makes debugging of errors in timers much easier, because the log message includes the name of the scheduled job/timer which failed.

Signed-off-by: Florian Hotze florianh_dev@icloud.com

rkoshak commented 2 years ago

I have this on my todo but I want to apply it to all of my libraries that create timers, not just timer manager. I also want to have it default to the ruleUID (if it's defined) if a name for the timer wasn't provided for the timer's name. I'd rather not just blindly use the key as the name (maybe use that if a name and the ruleUID isn't defined) because the same key might be used to create timers in multiple rules.

Because I want to do this for all the timer libs (which is pretty much everything in this repo) I was thinking of consolidating the creation of the timers into a utility function and have all the other libraries call that. That way we have one place to update should something like this change about creating timers in the future.

I've already implemented something like this for looping timer (without the central helper function) but haven't checked it in yet.

class LoopingTimer {

  /**
   * Constructor
   */
  constructor(name) {
    // this.name = (name) ? name : 'loopingTimer';
    this.name = (name) ? name : (ruleUID) ? ruleUID : 'loopingTimer';
  }
...
rkoshak commented 2 years ago

I created an issue to track this. #70

florian-h05 commented 2 years ago

I understand your point, I'll have a look at the issue and update this PR when I've got some time.