Improved error handling.
This commit is contained in:
parent
acea1b08c9
commit
78f5cc3938
1 changed files with 16 additions and 5 deletions
|
@ -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}"
|
||||||
|
|
Loading…
Reference in a new issue