]> git.ipfire.org Git - oddments/collecty.git/commitdiff
daemon: Collect every plugin immediately after daemon launched
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Sep 2020 09:27:19 +0000 (09:27 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Sep 2020 09:29:42 +0000 (09:29 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/collecty/daemon.py

index 8263291f2e58a38b557dc6c58d8981335d1a5890..e55b3a680e11013dcbafba615a1b8ae55590d425 100644 (file)
@@ -64,12 +64,7 @@ class Collecty(object):
                # get from there.
                self.bus = bus.Bus(self)
 
-               # Add all plugins
-               for plugin in plugins.get():
-                       self.add_plugin(plugin)
-
-               log.debug(_("Collecty successfully initialized with %s plugins") \
-                       % len(self.plugins))
+               log.debug(_("Collecty successfully initialized"))
 
        def add_plugin(self, plugin_class):
                # Try initialising a new plugin. If that fails, we will log the
@@ -82,20 +77,23 @@ class Collecty(object):
 
                self.plugins.append(plugin)
 
+               # Collect immediately
+               self._schedule_plugin(plugin, interval=0)
+
        @property
        def templates(self):
                for plugin in self.plugins:
                        for template in plugin.templates:
                                yield template
 
-       def _schedule_plugin(self, plugin):
+       def _schedule_plugin(self, plugin, interval=None):
                """
                        Schedules a collection event for the given plugin
                """
                log.debug("Scheduling plugin %s for executing in %ss" % (plugin, plugin.interval))
 
                self.scheduler.enter(
-                       plugin.interval, plugin.priority, self._collect, (plugin,),
+                       plugin.interval if interval is None else interval, plugin.priority, self._collect, (plugin,),
                )
 
        def _schedule_commit(self):
@@ -139,9 +137,9 @@ class Collecty(object):
                # Start the bus
                self.bus.start()
 
-               # Add all plugins to the scheduler
-               for plugin in self.plugins:
-                       self._schedule_plugin(plugin)
+               # Add all plugins
+               for plugin in plugins.get():
+                       self.add_plugin(plugin)
 
                # Run the scheduler
                try:
@@ -149,6 +147,9 @@ class Collecty(object):
                except KeyboardInterrupt:
                        pass
 
+               # Clear all plugins
+               self.plugins.clear()
+
                # Stop the bus thread
                self.bus.shutdown()