]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/mgr_util: make RTimer calss reusable
authorVenky Shankar <vshankar@redhat.com>
Thu, 9 Jul 2020 10:43:04 +0000 (06:43 -0400)
committerVenky Shankar <vshankar@redhat.com>
Tue, 19 Jan 2021 06:06:43 +0000 (01:06 -0500)
Signed-off-by: Venky Shankar <vshankar@redhat.com>
src/pybind/mgr/mgr_util.py

index a9d3f76f236053e0eeeb655159d7c84904693c5a..e30359952501520bf2182b88762f89103e32f1cc 100644 (file)
@@ -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: