Skip to content

Commit

Permalink
make read_rules multithread save
Browse files Browse the repository at this point in the history
  • Loading branch information
bledig-osp committed Mar 10, 2015
1 parent 98cfc1a commit 1afe79d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/tuersteher.rb
Expand Up @@ -8,6 +8,7 @@

require 'singleton'
require 'logger'
require 'thread'

module Tuersteher

Expand Down Expand Up @@ -46,6 +47,7 @@ def initialize
@path_rules = []
@model_rules = []
@check_intervall = 300 # set default check interval to 5 minutes
@mutex = Mutex.new
end

def ready?
Expand Down Expand Up @@ -103,9 +105,12 @@ def eval_rules rules_definitions
# config/access_rules.rb
def read_rules
@was_read = false
content = File.read self.rules_config_file
if content
eval_rules content
@mutex.synchronize do
return if @was_read # dann hat ein anderer Thread bereits gelesen
content = File.read self.rules_config_file
if content
eval_rules content
end
end
rescue => ex
Tuersteher::TLogger.logger.error "Tuersteher::AccessRulesStorage - Error in rules: #{ex.message}\n\t"+ex.backtrace.join("\n\t")
Expand Down
2 changes: 1 addition & 1 deletion tuersteher.gemspec
Expand Up @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)

Gem::Specification.new do |s|
s.name = 'tuersteher'
s.version = '0.7.1'
s.version = '0.7.2'
s.authors = ["Bernd Ledig"]
s.email = ["bernd@ledig.info"]
s.homepage = "http://github.com/bledig/tuersteher"
Expand Down

0 comments on commit 1afe79d

Please sign in to comment.