Skip to content

Commit

Permalink
Improve settings shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
titilambert committed Sep 1, 2017
1 parent a703483 commit 0fa3c47
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions tuxeatpi_common/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def start(self):
def shutdown(self):
"""Shutdown the daemon form mqtt message"""
self.logger.info("Stopping %s", self.name)
self.settings.stop()
self._tasks_thread.stop()
self._mqtt_client.stop()
self._run_main_loop = False
Expand Down
10 changes: 8 additions & 2 deletions tuxeatpi_common/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, component):
self.language = None
self.nlu_engine = None
self.params = {}
self._wait_config = True

def save(self, value, key=None):
"""Serialize (json) value and save it in etcd"""
Expand All @@ -48,12 +49,17 @@ def delete(self, key=None):
except etcd.EtcdKeyNotFound:
pass

def stop(self):
"""Stop waiting for settings"""
self.logger.info("Stopping settings")
self._wait_config = False

async def read(self, watch=False):
"""Watch for component settings change in etcd
This is done by the subtaskers
"""
while True:
while self._wait_config:
try:
raw_data = await self.etcd_client.read(self.key, wait=watch)
except aio_etcd.EtcdKeyNotFound:
Expand All @@ -75,7 +81,7 @@ async def read_global(self, watch=False):
This is done by the subtaskers
"""
while True:
while self._wait_config:
try:
raw_data = await self.etcd_client.read(self.global_key, wait=watch)
except aio_etcd.EtcdKeyNotFound:
Expand Down

0 comments on commit 0fa3c47

Please sign in to comment.