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

When state expires allow to set a default value instead of "NULL" the state object

Open DutchmanNL opened this issue 4 years ago • 9 comments

Current behavior : using the setstate expire will result in a NULL value at the state after time has reached.

Wanted behavior : more flexibility for assigning an "expire" value to developers

Suggestion : implement SetState {expireDef : >time<) which will use the def value of an state object to set after timeout has reached.

I see several situation were I would. like to use the default value at state expire instead of NULL. example online status : will. be set at polling time and set to false at time reached Have the default false value here is more efficient and understandable than NULL.

relation to https://github.com/ioBroker/ioBroker.js-controller/issues/665

DutchmanNL avatar Feb 13 '20 18:02 DutchmanNL

The realization will be tricky ... expires are currently handled "redis style" which means that really the complete state value gets deleted. Independetly if controller is running or not ...

So to realize this we need to completely rebuild expiry handling :-(

Apollon77 avatar Feb 13 '20 21:02 Apollon77

So I guess currently it’s just a SETEX redis command. Redis does not provide a logic to expire and set a new value on expire. Expiration always means deletion.

So maybe it’s better to keep the mechanics of the current function and describe the mechanics in the docs. We could create a separate method setStateTimeout or something like this for this use case, using timeout and clearing the timeout if state gets changed before timeout executes.

foxriver76 avatar Feb 13 '20 22:02 foxriver76

So I guess currently it’s just a SETEX redis command. Redis does not provide a logic to expire and set a new value on expire. Expiration always means deletion.

Exactly. this is the only "easy" way to handle this with a real redis as data store. There could be ways like additional "SETs" or such that can be used, but also means more effort and complexity.

Apollon77 avatar Feb 13 '20 23:02 Apollon77

We could create a separate method setStateTimeout or something like this for this use case, using timeout and clearing the timeout if state gets changed before timeout executes.

sounds like a plan, currently this is my workaround to implement the kind of. functionality. into adapters. But would be more nice to have it handled by the backend.

DutchmanNL avatar Feb 14 '20 07:02 DutchmanNL

But the problem is then that this gets lost when the adapter (if adapter is doing it) or controller (if controller is doing it) gets restarted or such. So it is no 100% solution

Apollon77 avatar Feb 14 '20 11:02 Apollon77

It depends. Is the goal really to build a 1:1 behavior of redis expire or is it enough on controller level. To rebuild redis behavior it is probably lots of overhead (would decline it).

We would need to store the timeouts in a separate State and delete them in the state on execution and on controller startage check if there are expired timeouts, if so, set state now (which would also not be exactly like redis), else start a timeout with the remaining time...

foxriver76 avatar Feb 14 '20 11:02 foxriver76

Yes we need to solve it with "redis mechanisms only" because we need to support having Redis as DB too ... I think there could be ways (like special keys that store these expiry infos and after that checks/reacts on key changes ... but this is not "simple" ;-)

I would not plan it into any version as of now and we see how often we stumble over it in the future

Apollon77 avatar Feb 14 '20 11:02 Apollon77

Guess, this one is a duplicate: https://github.com/ioBroker/ioBroker.js-controller/issues/650 - I would keep the current issue open due to our discussion, even though the other one was there before.

foxriver76 avatar Feb 14 '20 15:02 foxriver76

Guess, this one is a duplicate: #650 -

Yes, stupid me ...

DutchmanNL avatar Feb 14 '20 17:02 DutchmanNL