]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
journal, integrated in bot
authorMatthias Hecker <apoc@geekosphere.org>
Sun, 14 Jun 2015 18:52:47 +0000 (20:52 +0200)
committerMatthias Hecker <apoc@geekosphere.org>
Sun, 14 Jun 2015 18:52:47 +0000 (20:52 +0200)
lib/rbot/ircbot.rb
lib/rbot/journal.rb
lib/rbot/journal/postgres.rb

index eb158c6329fcb1a55a169b50fc3f80d086b35b66..caabc15dc325f769ca7932cc4ba69b4de99980b5 100644 (file)
@@ -156,6 +156,7 @@ require 'rbot/registry'
 require 'rbot/plugins'
 require 'rbot/message'
 require 'rbot/language'
+require 'rbot/journal'
 
 module Irc
 
@@ -201,8 +202,12 @@ class Bot
   # loads and opens new registry databases, used by the plugins
   attr_accessor :registry_factory
 
+  # web service
   attr_accessor :webservice
 
+  # persistent message queue
+  attr_accessor :journal
+
   # server we are connected to
   # TODO multiserver
   def server
@@ -545,6 +550,8 @@ class Bot
 
     log_session_start
 
+    @journal = Journal::JournalBroker.new(bot: self)
+
     if $daemonize
       log "Redirecting standard input/output/error"
       [$stdin, $stdout, $stderr].each do |fd|
index a25f3a9f9632aaf0d874223cf1b8fd345a5753d9..5045f9d53563953e4df5288d9e6392b88db028f7 100644 (file)
@@ -125,8 +125,8 @@ module Journal
       end
     end
 
-    def create(name, uri)
-      log 'load journal storage adapter: ' + name
+    def self.create(name, uri)
+      warning 'load journal storage adapter: ' + name
       load File.join(File.dirname(__FILE__), 'journal', name + '.rb')
       cls = AbstractStorage.get_impl.first
       cls.new(uri: uri)
@@ -285,6 +285,7 @@ module Journal
     def initialize(opts={})
       # overrides the internal consumer with a block
       @consumer = opts[:consumer]
+      @bot = opts[:bot]
       # storage backend
       if @bot
         @storage = opts[:storage] || Storage.create(
@@ -292,6 +293,9 @@ module Journal
       else
         @storage = opts[:storage]
       end
+      unless @storage
+        warning 'journal broker: no storage set up, won\'t persist messages'
+      end
       @queue = Queue.new
       # consumer thread:
       @thread = Thread.new do
index 65c67eb94c5ce2e7ca8384e989f366ed98820463..c62d4c97b1fe0217874805a03949fcea8b3c241d 100644 (file)
@@ -22,6 +22,7 @@ module Journal
       def initialize(opts={})
         @uri = opts[:uri] || 'postgresql://localhost/rbot_journal'
         @conn = PG.connect(@uri)
+        @conn.exec('set client_min_messages = warning')
         @version = @conn.exec('SHOW server_version;')[0]['server_version']
 
         @version.gsub!(/^(\d+\.\d+)$/, '\1.0')