Improved error handling.

This commit is contained in:
Martin Edenhofer 2014-04-24 07:49:30 +02:00
parent acea1b08c9
commit 78f5cc3938

View file

@ -267,8 +267,9 @@ module Sessions
puts "/LOOP WORKER #{user_id} - #{count}" puts "/LOOP WORKER #{user_id} - #{count}"
end end
def self.thread_client(client_id, count) def self.thread_client(client_id, count, try_count = 0, try_run_time = Time.now)
puts "LOOP #{client_id} - #{count}" puts "LOOP #{client_id} - #{count}"
begin begin
Sessions::Client.new(client_id) Sessions::Client.new(client_id)
rescue => e rescue => e
@ -279,11 +280,21 @@ module Sessions
rescue => e rescue => e
puts "Can't reconnect to database #{ e.inspect }" puts "Can't reconnect to database #{ e.inspect }"
end end
ct = count++1
if ct < 10 try_run_max = 10
thread_client(client_id, ct) try_count += 1
# reset error counter if to old
if try_run_time + ( 60 * 5 ) < Time.now
try_count = 0
end
try_run_time = Time.now
# restart job again
if try_run_max > try_count
thread_client(client_id, ct, try_count, try_run_time)
else else
raise "STOP thread_client for client #{client_id} after 10 tries" raise "STOP thread_client for client #{client_id} after #{try_run_max} tries"
end end
end end
puts "/LOOP #{client_id} - #{count}" puts "/LOOP #{client_id} - #{count}"