ioBroker.js-controller icon indicating copy to clipboard operation
ioBroker.js-controller copied to clipboard

Allow "randomization of schedules" for schedule adapters

Open Apollon77 opened this issue 3 years ago • 7 comments

We should find a way to randomize the defaut schedule for schedule adapters, if the start is not required to be exactly at a special time; and especially when external systems are queried (see yr and tankerkoenig case).

We could allow placeholders like "X * * * *" in the io-package config where X is then on instance creation being replaced by a random number. We also could be able to find solutions to allow "every 5 minutes" schedules.

We could also allow (or by default?) delay the start within the minute by some random seconds on start to make sure the run is also spread in the respective minute.

Apollon77 avatar Mar 01 '22 20:03 Apollon77

My thoughts, as I mentioned offline:

  • simple placeholders don't allow specifying how often an adapter should run. What's X? Every 5 minutes? Every 15 minutes?
  • randomization would allow us to spread out the start:
    • On first start after controller start, figure out how long until the next scheduled start and delay a random amount of seconds between 0 and that duration
    • remember the duration and delay all following starts by that
    • needs an opt-out for "precise" adapter starts
  • "every 5 minutes" schedules would be a simple way IMO, but they would have to override the CRON somehow

AlCalzone avatar Mar 01 '22 21:03 AlCalzone

https://man.openbsd.org/crontab.5

A random value (within the legal range) may be obtained by using the ‘~’ character in a field. The interval of the random value may be specified explicitly, for example “0~30” will result in a random value between 0 and 30 inclusive. If either (or both) of the numbers on either side of the ‘~’ are omitted, the appropriate limit (low or high) for the field will be used.

klein0r avatar Mar 02 '22 21:03 klein0r

I don't think that's supported by node-scheduler, which uses cron-parser internally: https://github.com/harrisiirak/cron-parser/blob/f687555f25ff0e4e12a951f3a4827b382436692f/lib/expression.js#L125-L135

AlCalzone avatar Mar 02 '22 21:03 AlCalzone

Unfortunately not, would have been too easy 😀

foxriver76 avatar Mar 02 '22 21:03 foxriver76

Came up in Discord today: Randomization shouldn't be done for manual starts. If the user wants to test something, adding a random delay of several seconds to minutes will be confusing and prolong the test iterations.

AlCalzone avatar Mar 08 '22 13:03 AlCalzone