Class: Appshot::MongoDB

Inherits:
Object
  • Object
show all
Defined in:
lib/appshot/app/mongodb.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ MongoDB

Returns a new instance of MongoDB.



4
5
6
7
# File 'lib/appshot/app/mongodb.rb', line 4

def initialize(opts={})
  @port         = opts[:port]             || 27017
  @mongo_binary = opts[:database_command] || "mongo"
end

Instance Method Details

#call(call_chain) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/appshot/app/mongodb.rb', line 9

def call(call_chain)
  next_action = call_chain.shift
  lock
  next_action.call(call_chain) unless next_action.nil?
ensure
  unlock
end

#lockObject



17
18
19
# File 'lib/appshot/app/mongodb.rb', line 17

def lock
  %x[#{@mongo_binary} --host localhost:#{@port} --eval "db.fsyncLock()"]
end

#unlockObject



21
22
23
# File 'lib/appshot/app/mongodb.rb', line 21

def unlock
  %x[#{@mongo_binary} --host localhost:#{@port} --eval "db.fsyncUnlock()"]
end