DPIclimate / broker

3 stars 3 forks source link

Device mappings may overlap #13

Open dajtxx opened 1 year ago

dajtxx commented 1 year ago

If a new device mapping is created for a currently mapped logical device, the current and new device mapping rows may overlap.

A mapping object with a start time is provided to the insert_mapping function. The start time will likely be some small fraction of a second in the past because it was set by the caller.

insert_mapping calls _end_mapping for the logical device, and _end_mapping sets the end time of the current mapping to now(). This is likely slightly after the start time for the new mapping given to insert_mapping.

So when insert_mapping is finished, the previous mapping may have an end time slightly later than the start time of the current mapping.

_end_mapping (and end_mapping) should take an optional datetime object to use for the end time, and insert_mapping could pass the start time of the new mapping in.

This might also be useful for unit tests, allowing them to end mappings at specific times.

It probably isn't a bad bug as long as we usually use the start times of mappings in queries. The end time is more like a flag value to say a row is not a current mapping. Also, the chance of getting a message or some other signal that causes a query that happens right on a mapping change boundary is slim.