Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
gravel: ctrl/svc: cleanup watcher on shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: Joao Eduardo Luis <joao@suse.com>
  • Loading branch information
jecluis committed Apr 12, 2021
1 parent ba50e74 commit 44d0224
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/gravel/controllers/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# GNU General Public License for more details.

from enum import Enum
from typing import Dict, List, Tuple
from typing import Dict, List, Optional, Tuple
from logging import Logger
from fastapi.logger import logger as fastapi_logger
from pydantic import BaseModel
Expand Down Expand Up @@ -133,6 +133,7 @@ class Services(Ticker):

_services: Dict[str, ServiceModel]
_ready: bool
_state_watcher_id: Optional[int]

def __init__(self):
super().__init__(
Expand All @@ -141,6 +142,7 @@ def __init__(self):
)
self._services = {}
self._ready = False
self._state_watcher_id = None

def _is_ready(self) -> bool:
nodemgr: NodeMgr = get_node_mgr()
Expand All @@ -157,6 +159,12 @@ async def _do_tick(self) -> None:
self._ready = True
logger.debug(f"tick {len(self._services)} services")

async def shutdown(self) -> None:
logger.info("shutdown services")
if self._state_watcher_id:
nodemgr = get_node_mgr()
await nodemgr.store.cancel_watch(self._state_watcher_id)

async def create(
self,
name: str,
Expand Down Expand Up @@ -454,7 +462,8 @@ def _cb(key: str, value: str) -> None:
self._load_state(value)

nodemgr = get_node_mgr()
await nodemgr.store.watch("/services/state", _cb)
self._state_watcher_id = \
await nodemgr.store.watch("/services/state", _cb)


_services: Services = Services()
Expand Down

0 comments on commit 44d0224

Please sign in to comment.