Moves appointment deletion + db update to the cleaner

This commit is contained in:
Sergi Delgado Segura
2019-11-07 16:36:55 +00:00
parent 82f9de1717
commit 8b2f0efa2f
2 changed files with 24 additions and 17 deletions

View File

@@ -18,7 +18,7 @@ logger = Logger("Watcher")
class Watcher:
def __init__(self, db_manager, responder=None, max_appointments=MAX_APPOINTMENTS):
def __init__(self, db_manager, pisa_sk_file=PISA_SECRET_KEY, responder=None, max_appointments=MAX_APPOINTMENTS):
self.appointments = dict()
self.locator_uuid_map = dict()
self.asleep = True
@@ -30,7 +30,7 @@ class Watcher:
if not isinstance(responder, Responder):
self.responder = Responder(db_manager)
if PISA_SECRET_KEY is None:
if pisa_sk_file is None:
raise ValueError("No signing key provided. Please fix your pisa.conf")
else:
with open(PISA_SECRET_KEY, "r") as key_file:
@@ -137,21 +137,10 @@ class Watcher:
block_hash,
)
# Delete the appointment
appointment = self.appointments.pop(uuid)
# If there was only one appointment that matches the locator we can delete the whole list
if len(self.locator_uuid_map[locator]) == 1:
self.locator_uuid_map.pop(locator)
else:
# Otherwise we just delete the appointment that matches locator:appointment_pos
self.locator_uuid_map[locator].remove(uuid)
# DISCUSS: instead of deleting the appointment, we will mark it as triggered and delete it from both
# the watcher's and responder's db after fulfilled
# Update appointment in the db
appointment.triggered = True
self.db_manager.store_watcher_appointment(uuid, appointment.to_json())
# Delete the appointment and update db
Cleaner.delete_complete_appointment(
self.appointments, self.locator_uuid_map, locator, uuid, self.db_manager
)
# Register the last processed block for the watcher
self.db_manager.store_last_block_hash_watcher(block_hash)