Module: Offshore::Database
Constant Summary collapse
- LOCK_KEY =
"database:lock"
- SHUTDOWN_KEY =
"database:shutdown"
- SUITES_LIST_KEY =
"suites:list"
Instance Method Summary collapse
- #init ⇒ Object
- #lock ⇒ Object
- #redis ⇒ Object
- #reset ⇒ Object
- #rollback ⇒ Object
- #schema_snapshot ⇒ Object
- #shutdown ⇒ Object
- #startup ⇒ Object
- #unlock ⇒ Object
Instance Method Details
#init ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/offshore/server/database.rb', line 45 def init # TODO: how to let these finish and also stall startup. # should it be per test # what about db reconnections? Logger.info(" Database.init") Offshore::Database.unlock unless ENV['MULTI_OFFSHORE'] # no reason to keep everyone waiting if I'm the only one if redis.get(SHUTDOWN_KEY) Logger.info(" .... database shutting down. Exiting.") raise "Database shutting down. No new connections, please." end end |
#lock ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/offshore/server/database.rb', line 13 def lock Logger.info(" Database.lock") if Offshore::Mutex.lock(LOCK_KEY) Logger.info(" .... lock acquired") else Logger.info(" .... locked") raise Offshore::CheckBackLater.new("Database in use") end end |
#redis ⇒ Object
9 10 11 |
# File 'lib/offshore/server/database.rb', line 9 def redis Offshore.redis end |
#reset ⇒ Object
28 29 30 31 32 33 |
# File 'lib/offshore/server/database.rb', line 28 def reset Logger.info(" Database.reset") redis.del(LOCK_KEY) redis.del(SHUTDOWN_KEY) redis.del(SUITES_LIST_KEY) end |
#rollback ⇒ Object
64 65 66 67 |
# File 'lib/offshore/server/database.rb', line 64 def rollback Logger.info(" Database.rollback") snapshot.rollback end |
#schema_snapshot ⇒ Object
59 60 61 62 |
# File 'lib/offshore/server/database.rb', line 59 def schema_snapshot Logger.info(" Database.schema_snapshot") snapshot.create end |
#shutdown ⇒ Object
40 41 42 43 |
# File 'lib/offshore/server/database.rb', line 40 def shutdown Logger.info(" Database.shutdown") redis.incr(SHUTDOWN_KEY, 1) end |