I am using Authlogic with the logout timeout. What I need to do is log when the User has actually timed out. I have gone so far as to try to make a t开发者_如何学Chread that notices users that go away from the User.logged_in
list.
It seems when I put a thread in there I get 2 threads rather then one, so I am looking for a better solution.
What would be the best way to do this?
I ended up fixing my threading by putting the following at the top of the application controller:
def check_logout
previous_user = {}
loop {
x = User.logged_in
active_user = {}
x.each { |a|
active_user[a[:login]] = a[:login]
previous_user[a[:login]] = a[:login]
}
puts "active = #{active_user}"
previous_user.each { |key,value|
if active_user[key] == nil then
puts "Login timeout for #{value}"
InternalLog.notify_msg("Login timeout for #{value}")
previous_user.delete(key)
end
}
sleep(30)
}
rescue => e0
puts "WORKER THREAD RESCUE"
puts e0
exit end
if $BACKGROUND_THREAD == nil then
$BACKGROUND_THREAD = Thread.new do
check_logout
end
end
精彩评论