Skip to content

Commit

Permalink
Add a connection lock
Browse files Browse the repository at this point in the history
Fixes #80
  • Loading branch information
nviennot committed Aug 15, 2014
1 parent 8bfb44f commit 5281d52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/no_brainer/query_runner.rb
Expand Up @@ -11,7 +11,8 @@ def initialize(runner)
end

autoload :Driver, :DatabaseOnDemand, :TableOnDemand, :WriteError,
:Reconnect, :Selection, :RunOptions, :Logger, :MissingIndex
:Reconnect, :Selection, :RunOptions, :Logger, :MissingIndex,
:ConnectionLock

class << self
attr_accessor :stack
Expand All @@ -32,6 +33,7 @@ def run(*args, &block)
use DatabaseOnDemand
use TableOnDemand
use Logger
use ConnectionLock
use Reconnect
use Driver
end
Expand Down
7 changes: 7 additions & 0 deletions lib/no_brainer/query_runner/connection_lock.rb
@@ -0,0 +1,7 @@
class NoBrainer::QueryRunner::ConnectionLock < NoBrainer::QueryRunner::Middleware
@@lock = Mutex.new

def call(env)
@@lock.synchronize { @runner.call(env) }
end
end

0 comments on commit 5281d52

Please sign in to comment.