From: Michael Tremer Date: Sat, 1 Sep 2012 18:00:58 +0000 (+0000) Subject: Take running time of plugins into account when calculating interval. X-Git-Tag: 0.0.2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0fc8c5dd6f44f7f74ea7568db90d8e488a9dddc6;p=collecty.git Take running time of plugins into account when calculating interval. --- diff --git a/collecty/plugins/base.py b/collecty/plugins/base.py index b295657..2997d11 100644 --- a/collecty/plugins/base.py +++ b/collecty/plugins/base.py @@ -253,13 +253,22 @@ class DataSource(threading.Thread): """ This method catches errors from the read() method and logs them. """ + start_time = time.time() + try: - return self.read(*args, **kwargs) + data = self.read(*args, **kwargs) + if data is None: + self.log.warning(_("Received empty data.")) + else: + self.data.append("%d:%s" % (start_time, data)) # Catch any exceptions, so collecty does not crash. except Exception, e: self.log.critical(_("Unhandled exception in read()!"), exc_info=True) + # Return the elapsed time since _read() has been called. + return (time.time() - start_time) + def _submit(self, *args, **kwargs): """ This method catches errors from the submit() method and logs them. @@ -281,7 +290,9 @@ class DataSource(threading.Thread): # Wait until the timer has successfully elapsed. if self.timer.wait(): self.log.debug(_("Collecting...")) - self._read() + delay = self._read() + + self.timer.reset(delay) self._submit() self.log.debug(_("Stopped."))