plugin - adds tower state to TowerInfo

The state flags whether the tower is reachable or not so the user can be aware of it
This commit is contained in:
Sergi Delgado Segura
2020-04-23 16:30:05 +02:00
parent 7b3bc6e6a8
commit bc5f09000a
2 changed files with 18 additions and 9 deletions

View File

@@ -184,6 +184,7 @@ def add_appointment(plugin, **kwargs):
# Send appointment to the server.
# FIXME: sending the appointment to all registered towers atm. Some management would be nice.
for tower_id, tower in plugin.wt_client.towers.items():
tower_info = TowerInfo.from_dict(plugin.wt_client.db_manager.load_tower_record(tower_id))
try:
plugin.log("Sending appointment to the Eye of Satoshi at {}".format(tower.get("netaddr")))
add_appointment_endpoint = "{}/add_appointment".format(tower.get("netaddr"))
@@ -204,18 +205,24 @@ def add_appointment(plugin, **kwargs):
# TODO: Not storing the whole appointments for now. The node can recreate all the data if needed.
# DISCUSS: It may be worth checking that the available slots match instead of blindly trusting.
# Update TowersDB
tower_info = TowerInfo.from_dict(plugin.wt_client.db_manager.load_tower_record(tower_id))
tower_info.appointments[appointment.locator] = signature
tower_info.available_slots = response.get("available_slots")
plugin.wt_client.db_manager.store_tower_record(tower_id, tower_info)
tower_info.status = "reachable"
# Update memory
plugin.wt_client.towers[tower_id]["available_slots"] = response.get("available_slots")
# Update memory and TowersDB
plugin.wt_client.db_manager.store_tower_record(tower_id, tower_info)
plugin.wt_client.towers[tower_id] = tower_info.get_summary()
except TowerConnectionError as e:
# TODO: Implement retry logic
plugin.log(str(e))
if e.kwargs.get("transitory"):
tower_info.status = "temporarily unreachable"
else:
tower_info.status = "unreachable"
plugin.wt_client.towers[tower_id] = tower_info.get_summary()
plugin.wt_client.db_manager.store_tower_record(tower_id, tower_info)
except TowerResponseError as e:
plugin.log(str(e))