bellrichm / WeeWX-MQTTSubscribe

A WeeWX service and driver that receives data from MQTT.
GNU General Public License v3.0
52 stars 13 forks source link

expires_after does not always work #178

Open bellrichm opened 1 year ago

bellrichm commented 1 year ago

It is actually very broken in at least this one scenario:

WeeWX record_generation = hardware record_augmentation = True # obviously if this is False, then this would never work

MQTTSubscribe is running as a service expires_after = None binding = loop

This is a timing issue. Both MQTTSubscribe and StdArchive bind to ‘NEW_ARCHIVE_RECORD’ event. MQTTSubscribe handles it first. It looks at the archive record and sees that the data is missing. It then pulls the data from the cache (note, the value could be None). Then StdArchive handles the event. It looks at the archive record and sees that the field has a value (note, again the value could be None) and therefore does not augment the record. The result is the archive record always gets the value from the cache.

bellrichm commented 10 months ago

One solution When data is received (the on message callbacks), if the field is in the cache remove it. This would be near the call to _update_data method. I don’t like this because it spreads the interaction of the cache across the code base.

bellrichm commented 10 months ago

I thought about a separate cache service, but due to record_augmentation happening in stdArchive service, it would run into the same challenge that the cache would have to be cleared at the ‘loop level’. About the only benefit is separation of concerns.

bellrichm commented 10 months ago

Function test would be something like this

Some of these checks might not be necessary. Also might be separate into smaller chunks.