This adds a migrated flag to the framework.db object, to prevent a race condition between session_manager startup and db availability while the schema loads. This also makes the session_manager code try again (up to a max count) when it encounters an exception
git-svn-id: file:///home/svn/framework3/trunk@12529 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
e621828cac
commit
4c84181c44
|
@ -19,7 +19,7 @@ class DBManager
|
|||
# Returns true if we are ready to load/store data
|
||||
def active
|
||||
return false if not @usable
|
||||
(ActiveRecord::Base.connected? && ActiveRecord::Base.connection.active?)
|
||||
(ActiveRecord::Base.connected? && ActiveRecord::Base.connection.active? && migrated)
|
||||
end
|
||||
|
||||
# Returns true if the prerequisites have been installed
|
||||
|
@ -36,10 +36,14 @@ class DBManager
|
|||
|
||||
# Stores a TaskManager for serializing database events
|
||||
attr_accessor :sink
|
||||
|
||||
# Flag to indicate database migration has completed
|
||||
attr_accessor :migrated
|
||||
|
||||
def initialize(framework, opts = {})
|
||||
|
||||
self.framework = framework
|
||||
self.migrated = false
|
||||
@usable = false
|
||||
|
||||
# Don't load the database if the user said they didn't need it.
|
||||
|
@ -149,6 +153,7 @@ class DBManager
|
|||
nopts['pool'] = 75
|
||||
|
||||
begin
|
||||
self.migrated = false
|
||||
create_db(nopts)
|
||||
|
||||
# Configure the database adapter
|
||||
|
@ -159,6 +164,9 @@ class DBManager
|
|||
|
||||
# Set the default workspace
|
||||
framework.db.workspace = framework.db.default_workspace
|
||||
|
||||
# Flag that migration has completed
|
||||
self.migrated = true
|
||||
rescue ::Exception => e
|
||||
self.error = e
|
||||
elog("DB.connect threw an exception: #{e}")
|
||||
|
|
|
@ -31,6 +31,10 @@ class SessionManager < Hash
|
|||
|
||||
self.monitor_thread = framework.threads.spawn("SessionManager", true) do
|
||||
last_seen_timer = Time.now.utc
|
||||
|
||||
respawn_max = 30
|
||||
respawn_cnt = 0
|
||||
|
||||
begin
|
||||
while true
|
||||
|
||||
|
@ -136,8 +140,12 @@ class SessionManager < Hash
|
|||
# All session management falls apart when any exception is raised to this point. Log it.
|
||||
#
|
||||
rescue ::Exception => e
|
||||
wlog("Exception in monitor thread #{e.class} #{e}")
|
||||
wlog("Call Stack\n#{e.backtrace.join("\n")}", 'core', LEV_3)
|
||||
respawn_cnt += 1
|
||||
elog("Exception #{respawn_cnt}/#{respawn_max} in monitor thread #{e.class} #{e} #{e.backtrace.join("\n")}")
|
||||
if respawn_cnt < respawn_max
|
||||
::IO.select(nil, nil, nil, 10.0)
|
||||
retry
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue