diff options
-rw-r--r-- | lib/rbot/ircbot.rb | 7 | ||||
-rw-r--r-- | lib/rbot/journal.rb | 8 | ||||
-rw-r--r-- | lib/rbot/journal/postgres.rb | 1 |
3 files changed, 14 insertions, 2 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index eb158c63..caabc15d 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -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| diff --git a/lib/rbot/journal.rb b/lib/rbot/journal.rb index a25f3a9f..5045f9d5 100644 --- a/lib/rbot/journal.rb +++ b/lib/rbot/journal.rb @@ -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 diff --git a/lib/rbot/journal/postgres.rb b/lib/rbot/journal/postgres.rb index 65c67eb9..c62d4c97 100644 --- a/lib/rbot/journal/postgres.rb +++ b/lib/rbot/journal/postgres.rb @@ -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') |