pimoroni / enviro

MIT License
101 stars 79 forks source link

Secondary upload destination #189

Open sjefferson99 opened 11 months ago

sjefferson99 commented 11 months ago

Add a secondary upload destination in the config file that defaults to None.

Modified the __init__.py upload readings function to have a stab at the secondary upload once the full set of primary attempts are complete.

The secondary will not retry data if the primary is successful and equally the secondary will receive duplicates if the primary experiences issues on the previous pass.

This is designed to allow me to get extra diagnostic data to my influxdb while not interrupting the Wunderground data upload.

The above could be improved with better error handling logic if there is demand.

This makes improvements in the direction requested in #38 for more concurrent destinations.

gbravery commented 10 months ago

I had a play with this code (i.e. I wanted to use it in the future, so I thought I'd import it now, ready for when I really wanted it). However, I found if the secondary_destination was left as None, then the code began to error. Seemed to be around the import code: exec(f"import enviro.destinations.{secondary_destination}") secondary_destination_module = sys.modules[f"enviro.destinations.{secondary_destination}"] secondary_destination_module.log_destination()

I wonder if there is a safer way of doing this?

sjefferson99 commented 10 months ago

Yes, this was a bit rushed to get the data I needed in and not enough testing of each scenario.

Scanning the code it looks like the try for the whole block will fail on there being no module called "None" to import. A simple fix would be to put the module import in an "if secondary_destination:" block, although I suspect further work on try blocks would be better. There may be more fallout from expecting that module to exist etc. I vaguely recall having a lot of fun with all those tries and they are not my forte.

I'll set up None in config.py and develop something more robust, might take a few days, especially as my board has currently mysteriously fallen out with my DHCP server.

sjefferson99 commented 10 months ago

@gbravery I have put the if statements in for the secondary destination code. I've tested it works as expected with influxdb or None set. I might come back to this and make it look a little less hacky.