From: Michael Tremer Date: Sun, 5 Aug 2012 19:07:11 +0000 (+0000) Subject: Write all data to disk on SIGUSR1. X-Git-Tag: 0.0.2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5e502f7ae79eafb03f6c5e95e4c6c1b390b8b15;p=collecty.git Write all data to disk on SIGUSR1. --- diff --git a/collecty/__init__.py b/collecty/__init__.py index b7e1f22..afae3f5 100644 --- a/collecty/__init__.py +++ b/collecty/__init__.py @@ -110,8 +110,6 @@ class Collecty(object): # Regularly submit all data to disk. while self.running: - self.timer.reset() - if self.timer.wait(): self.submit_all() @@ -131,9 +129,13 @@ class Collecty(object): """ Submit all data right now. """ + log.debug(_("Submitting all data in memory")) for i in self.instances: i._submit() + # Schedule the next submit. + self.timer.reset() + def shutdown(self): log.debug(_("Received shutdown signal")) @@ -146,9 +148,18 @@ class Collecty(object): i.shutdown() def register_signal_handler(self): - for s in (signal.SIGTERM, signal.SIGINT): + for s in (signal.SIGTERM, signal.SIGINT, signal.SIGUSR1): + log.debug(_("Registering signal %d") % s) + signal.signal(s, self.signal_handler) - def signal_handler(self, *args, **kwargs): - # Shutdown this application. - self.shutdown() + def signal_handler(self, sig, *args, **kwargs): + log.info(_("Caught signal %d") % sig) + + if sig in (signal.SIGTERM, signal.SIGINT): + # Shutdown this application. + self.shutdown() + + elif sig == signal.SIGUSR1: + # Submit all data. + self.submit_all()