From: Venky Shankar Date: Thu, 9 Jul 2020 10:43:04 +0000 (-0400) Subject: pybind/mgr/mgr_util: make RTimer calss reusable X-Git-Tag: v17.0.0~17^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=296e879009a16130138c9f7aa09bfdbf29ff9847;p=ceph.git pybind/mgr/mgr_util: make RTimer calss reusable Signed-off-by: Venky Shankar --- diff --git a/src/pybind/mgr/mgr_util.py b/src/pybind/mgr/mgr_util.py index a9d3f76f2360..e30359952501 100644 --- a/src/pybind/mgr/mgr_util.py +++ b/src/pybind/mgr/mgr_util.py @@ -58,6 +58,20 @@ class CephfsConnectionException(Exception): def __str__(self) -> str: return "{0} ({1})".format(self.errno, self.error_str) +class RTimer(Timer): + """ + recurring timer variant of Timer + """ + @no_type_check + def run(self): + try: + while not self.finished.is_set(): + self.finished.wait(self.interval) + self.function(*self.args, **self.kwargs) + self.finished.set() + except Exception as e: + logger.error("task exception: %s", e) + raise class CephfsConnectionPool(object): class Connection(object): @@ -145,21 +159,6 @@ class CephfsConnectionPool(object): logger.info("abort done from cephfs '{0}'".format(self.fs_name)) self.fs = None - class RTimer(Timer): - """ - recurring timer variant of Timer - """ - @no_type_check - def run(self): - try: - while not self.finished.is_set(): - self.finished.wait(self.interval) - self.function(*self.args, **self.kwargs) - self.finished.set() - except Exception as e: - logger.error("CephfsConnectionPool.RTimer: %s", e) - raise - # TODO: make this configurable TIMER_TASK_RUN_INTERVAL = 30.0 # seconds CONNECTION_IDLE_INTERVAL = 60.0 # seconds @@ -169,9 +168,8 @@ class CephfsConnectionPool(object): self.connections: Dict[str, CephfsConnectionPool.Connection] = {} self.lock = Lock() self.cond = Condition(self.lock) - self.timer_task = CephfsConnectionPool.RTimer( - CephfsConnectionPool.TIMER_TASK_RUN_INTERVAL, - self.cleanup_connections) + self.timer_task = RTimer(CephfsConnectionPool.TIMER_TASK_RUN_INTERVAL, + self.cleanup_connections) self.timer_task.start() def cleanup_connections(self) -> None: