Module: Offshore::Database
Constant Summary collapse
- GENERATE_KEY =
"database:generate"
- 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(background = true) ⇒ Object
- #unlock ⇒ Object
Instance Method Details
#init ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/offshore/server/database.rb', line 48 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(" .... databse shutting down. Exiting.") raise "Database shutting down. No new connections, please." else create_schema(true) end end |
#lock ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/offshore/server/database.rb', line 14 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
10 11 12 |
# File 'lib/offshore/server/database.rb', line 10 def redis Offshore.redis end |
#reset ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/offshore/server/database.rb', line 29 def reset Logger.info(" Database.reset") redis.del(LOCK_KEY) redis.del(GENERATE_KEY) redis.del(SHUTDOWN_KEY) redis.del(SUITES_LIST_KEY) end |
#rollback ⇒ Object
69 70 71 72 |
# File 'lib/offshore/server/database.rb', line 69 def rollback Logger.info(" Database.rollback") snapshot.rollback end |
#schema_snapshot ⇒ Object
64 65 66 67 |
# File 'lib/offshore/server/database.rb', line 64 def schema_snapshot Logger.info(" Database.schema_snapshot") snapshot.create end |
#shutdown ⇒ Object
43 44 45 46 |
# File 'lib/offshore/server/database.rb', line 43 def shutdown Logger.info(" Database.shutdown") redis.incr(SHUTDOWN_KEY, 1) end |