Commits

Josh VanderLinden  committed 49328b7

  • Participants
  • Parent commits 242b41e

Comments (0)

Files changed (1)

File rethinklog.py

 Copyright (C) 2013 Josh VanderLinden <arch@cloudlery.com>
 
 Date: 2013-02-07
-Version: 0.0.1
+Version: 0.0.2
+
+* 0.0.2 - 2013-02-07: bulk inserts; disconnect from rethinkdb
+* 0.0.1 - 2013-02-07: initial plugin
 
 """
 
 
 __name__ = 'RethinkLog'
 __author__ = 'codekoala'
-__version__ = '0.0.1'
+__version__ = '0.0.2'
 __license__ = 'MIT'
 __description__ = 'Log messages to a RethinkDB cluster'
 
 
-weechat.register(__name__, __author__, __version__, __license__, __description__, '', '')
+weechat.register(__name__, __author__, __version__, __license__, __description__, 'close', '')
 
 
 defaults = dict(
         weechat.config_set_plugin(o, v)
 
 
+# TODO: handle error cases when RethinkDB is inaccessible
+# TODO: handle errors inserting records (retries?)
+# TODO: configuration changes withour requiring a reload
+# TODO: show most recent logs for a given buffer when opened
+
+
 class RethinkLogger(object):
     """Log messages to a RethinkDB cluster"""
 
 
         return_code = weechat.WEECHAT_RC_OK
 
-        while True:
-            try:
-                record = self.queue.popleft()
-            except IndexError:
-                break
+        try:
+            self.r.insert(self.queue).run()
+        except Exception as e:
+            weechat.prnt('', 'Failed to log messages to rethinkdb: %s' % str(e))
+            return_code = weechat.WEECHAT_RC_ERROR
 
-            try:
-                self.r.insert(record).run()
-            except Exception as e:
-                self.queue.appendleft(record)
-                weechat.prnt('', 'Failed to log messages to rethinkdb: %s' % str(e))
-                return_code = weechat.WEECHAT_RC_ERROR
-                break
+        # TODO: handle errors instead of postentially dropping a ton of records
+        self.queue.clear()
 
         return return_code
 
+    def close(self):
+        """Disconnect from the RethinkDB"""
+
+        if self.cnx:
+            self.cnx.close()
+
 
 plugin = RethinkLogger()
 log = plugin.log
 flush = plugin.flush
+close = plugin.close
 
 weechat.hook_print('', '', '', 1, 'log', '')
 weechat.hook_timer(5000, 0, 0, 'flush', '')