Class: ActiveRecord::ConnectionAdapters::Mysql2Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord-mysql2-retry-ext.rb

Instance Method Summary collapse

Instance Method Details

#exec_query_with_retry(*args) ⇒ Object Also known as: exec_query

exec_query_with_retry tries the attempted query and retries it up to 5 times before raising an ActiveRecord::StatementInvalid exception.



7
8
9
10
11
12
13
14
15
16
# File 'lib/activerecord-mysql2-retry-ext.rb', line 7

def exec_query_with_retry(*args)
  retry_count = 0
  begin
    exec_query_without_retry *args
  rescue ActiveRecord::StatementInvalid => ex
    retry_count +=1
    retry if retry_count < 5
    raise ex
  end
end