mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 22:24:23 +01:00
Moves awaking / sleeping functionality to their own methods
This commit is contained in:
@@ -146,6 +146,17 @@ class Responder:
|
||||
self.chain_monitor = chain_monitor
|
||||
self.db_manager = db_manager
|
||||
|
||||
def awake(self):
|
||||
self.asleep = False
|
||||
self.chain_monitor.responder_asleep = False
|
||||
Thread(target=self.do_watch).start()
|
||||
|
||||
def sleep(self):
|
||||
self.asleep = True
|
||||
self.chain_monitor.responder_asleep = True
|
||||
|
||||
logger.info("No more pending trackers, going back to sleep")
|
||||
|
||||
@staticmethod
|
||||
def on_sync(block_hash):
|
||||
"""
|
||||
@@ -265,9 +276,7 @@ class Responder:
|
||||
)
|
||||
|
||||
if self.asleep:
|
||||
self.asleep = False
|
||||
self.chain_monitor.responder_asleep = False
|
||||
Thread(target=self.do_watch).start()
|
||||
self.awake()
|
||||
|
||||
def do_watch(self):
|
||||
"""
|
||||
@@ -321,10 +330,7 @@ class Responder:
|
||||
prev_block_hash = block.get("hash")
|
||||
|
||||
# Go back to sleep if there are no more pending trackers
|
||||
self.asleep = True
|
||||
self.chain_monitor.responder_asleep = True
|
||||
|
||||
logger.info("No more pending trackers, going back to sleep")
|
||||
self.sleep()
|
||||
|
||||
def check_confirmations(self, txs):
|
||||
"""
|
||||
|
||||
@@ -76,6 +76,19 @@ class Watcher:
|
||||
if not isinstance(responder, Responder):
|
||||
self.responder = Responder(db_manager, chain_monitor)
|
||||
|
||||
def awake(self):
|
||||
self.asleep = False
|
||||
self.chain_monitor.watcher_asleep = False
|
||||
Thread(target=self.do_watch).start()
|
||||
|
||||
logger.info("Waking up")
|
||||
|
||||
def sleep(self):
|
||||
self.asleep = True
|
||||
self.chain_monitor.watcher_asleep = True
|
||||
|
||||
logger.info("No more pending appointments, going back to sleep")
|
||||
|
||||
def add_appointment(self, appointment):
|
||||
"""
|
||||
Adds a new appointment to the ``appointments`` dictionary if ``max_appointments`` has not been reached.
|
||||
@@ -118,11 +131,7 @@ class Watcher:
|
||||
self.locator_uuid_map[appointment.locator] = [uuid]
|
||||
|
||||
if self.asleep:
|
||||
self.asleep = False
|
||||
self.chain_monitor.watcher_asleep = False
|
||||
Thread(target=self.do_watch).start()
|
||||
|
||||
logger.info("Waking up")
|
||||
self.awake()
|
||||
|
||||
self.db_manager.store_watcher_appointment(uuid, appointment.to_json())
|
||||
self.db_manager.create_append_locator_map(appointment.locator, uuid)
|
||||
@@ -208,10 +217,7 @@ class Watcher:
|
||||
self.db_manager.store_last_block_hash_watcher(block_hash)
|
||||
|
||||
# Go back to sleep if there are no more appointments
|
||||
self.asleep = True
|
||||
self.chain_monitor.watcher_asleep = True
|
||||
|
||||
logger.info("No more pending appointments, going back to sleep")
|
||||
self.sleep()
|
||||
|
||||
def get_breaches(self, txids):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user