New dep: robustserver. BDB::Env will reopen on error. Version 0.0.2

This commit is contained in:
Denis Knauf 2010-03-02 14:10:58 +01:00
parent 1989ade585
commit 34bb509b92
4 changed files with 27 additions and 50 deletions

View file

@ -13,6 +13,7 @@ begin
gem.files = ["README.md", "VERSION", "bin/**/*", "lib/**/*.rb", "test/**/*.rb"] gem.files = ["README.md", "VERSION", "bin/**/*", "lib/**/*.rb", "test/**/*.rb"]
gem.require_paths = ["bin"] gem.require_paths = ["bin"]
gem.add_dependency 'sbdb' gem.add_dependency 'sbdb'
gem.add_dependency 'robustserver'
gem.add_dependency 'select' gem.add_dependency 'select'
end end
Jeweler::GemcutterTasks.new Jeweler::GemcutterTasks.new

View file

@ -1 +1 @@
0.0.1 0.0.2

View file

@ -5,8 +5,11 @@ require 'sbdb'
require 'uuidtools' require 'uuidtools'
require 'socket' require 'socket'
require 'select' require 'select'
require 'robustserver'
class S2L < Select::Server class S2L < Select::Server
attr_accessor :dbs
def init p def init p
super p super p
@dbs = p[:dbs] @dbs = p[:dbs]
@ -105,58 +108,28 @@ class Rotate
alias emit put alias emit put
end end
class Retries class Main < RobustServer
attr_accessor :max, :range def initialize conf
attr_reader :count, :last super
@conf = conf
def initialize max = 10, range = 10
@max, @range, @count, @last = max, range, 0, Time.now
end
def retry?
@count = @last + @range > Time.now ? @count + 1 : 1
@last = Time.now
@count < @max
end
def run ex, &e
begin e.call *args
rescue ex
retries.retry? and retry
end
end
end
$conf = {
:home => 'logs',
:server => [ '', 1514],
:retries => [1,1] # [10, 10]
}
info :create => {:home => $conf[:home]}
Dir.mkdir $conf[:home] rescue Errno::EEXIST
info :open => SBDB::Env
SBDB::Env.new( $conf[:home], SBDB::CREATE | SBDB::Env::INIT_TRANSACTION | Bdb::DB_AUTO_COMMIT) do |dbenv|
info :open => Rotate
dbs = Rotate.new dbenv[ 'rotates.db', :type => SBDB::Btree, :flags => SBDB::CREATE | Bdb::DB_AUTO_COMMIT]
info :open => S2L info :open => S2L
serv = S2L.new :sock => TCPServer.new( *$conf[:server]), :dbs => dbs @serv = S2L.new :sock => TCPServer.new( *@conf[:server])
retries = Retries.new *$conf[:retries] info :create => {:home => @conf[:home]}
begin Dir.mkdir @conf[:home] rescue Errno::EEXIST
info :run => serv end
serv.run
info :shutdown => :stoped def run
rescue Interrupt info :open => SBDB::Env
info :shutdown => :interrupted SBDB::Env.new( @conf[:home], SBDB::CREATE | SBDB::Env::INIT_TRANSACTION | Bdb::DB_AUTO_COMMIT) do |dbenv|
rescue SignalException info :open => Rotate
info :shutdown => :signal @serv.dbs = Rotate.new dbenv[ 'rotates.db', :type => SBDB::Btree, :flags => SBDB::CREATE | Bdb::DB_AUTO_COMMIT]
rescue Object retries = Retries.new *@conf[:retries]
error :exception=>$!, :backtrace=>$!.backtrace info :run => @serv
retries.retry? and retry @serv.run
fatal "Too many retries (#{retries.count})" end
info :shutdown => :fatal
end end
info :close => dbenv
end end
Main.main :home => 'logs', :server => [ '', 1514], :retries => [1,1] # [10, 10]
info :halted info :halted

View file

@ -5,11 +5,11 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{syslog2logan} s.name = %q{syslog2logan}
s.version = "0.0.1" s.version = "0.0.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Denis Knauf"] s.authors = ["Denis Knauf"]
s.date = %q{2010-02-07} s.date = %q{2010-03-02}
s.default_executable = %q{s2l.rb} s.default_executable = %q{s2l.rb}
s.description = %q{Syslog-Server which logs to Berkeley Databases (No SyslogDaemon)} s.description = %q{Syslog-Server which logs to Berkeley Databases (No SyslogDaemon)}
s.email = %q{Denis.Knauf@gmail.com} s.email = %q{Denis.Knauf@gmail.com}
@ -35,13 +35,16 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<sbdb>, [">= 0"]) s.add_runtime_dependency(%q<sbdb>, [">= 0"])
s.add_runtime_dependency(%q<robustserver>, [">= 0"])
s.add_runtime_dependency(%q<select>, [">= 0"]) s.add_runtime_dependency(%q<select>, [">= 0"])
else else
s.add_dependency(%q<sbdb>, [">= 0"]) s.add_dependency(%q<sbdb>, [">= 0"])
s.add_dependency(%q<robustserver>, [">= 0"])
s.add_dependency(%q<select>, [">= 0"]) s.add_dependency(%q<select>, [">= 0"])
end end
else else
s.add_dependency(%q<sbdb>, [">= 0"]) s.add_dependency(%q<sbdb>, [">= 0"])
s.add_dependency(%q<robustserver>, [">= 0"])
s.add_dependency(%q<select>, [">= 0"]) s.add_dependency(%q<select>, [">= 0"])
end end
end end