So I've almost finished the DatabaseConnection class now I think, but one of the last things left is to figure out how to report query failures. Note that these should not happen in normal operation, so it could be argued that my current approach to handling this is sufficient.
Current (basic) approach to solving the problem
If a query is a write-only operation (for example adding a message to the event log), and the query fails, the pi will disconnect and then reconnect to the database and retry the query. If the query repeatedly fails (which should never happen) this will become an endless loop.
If a query is a read-only operation (for example getting the latest SUMP water level reading), and the query fails, the pi will disconnect and reconnect, and it will *NOT* try to execute that query again, instead signalling failure with a RuntimeError to the code that called the relevant method.
Ideas
- This approach might be just fine as it is, as query errors should not happen anyway.
- If we could figure out why a query failed, we could then take different actions depending on the reason, but it is not clear to me that we can do this.
- If we could report errors for write-only operations, that might be good.
- However, the corresponding methods do not currently wait for acknowledgement that the write worked - instead it is just guaranteed that eventually it will go through - it will retry forever.
- ^ There also doesn't seem to be any way to do this as far as I can tell.
- Any important read request should be repeated shortly anyway - how much does dumping the queries when they fail actually matter?
- ^ This is in contrast to writes - missing readings or events in the tables could be very bad for us.
- If he could be turned, he could become a powerful ally.