-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,14 +22,48 @@ def initialize(migration, connection = nil, options = {}) | |
@start = options[:start] || select_start | ||
@limit = options[:limit] || select_limit | ||
@printer = options[:printer] || Printer::Percentage.new | ||
@retry_on_deadlock = retry_on_deadlock(options.with_indifferent_access) | ||
@retry_attempts = retry_attempts(options.with_indifferent_access) | ||
@retry_wait_time = retry_wait_time(options.with_indifferent_access) | ||
end | ||
|
||
def execute | ||
return unless @start && @limit | ||
|
||
retries = 0 | ||
|
||
@next_to_insert = @start | ||
while @next_to_insert <= @limit | ||
stride = @throttler.stride | ||
affected_rows = @connection.update(copy(bottom, top(stride))) | ||
|
||
begin | ||
affected_rows = @connection.update(copy(bottom, top(stride))) | ||
rescue ActiveRecord::StatementInvalid => err | ||
if err.message.downcase.index('deadlock').nil? | ||
raise | ||
return | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
end | ||
|
||
if !@retry_on_deadlock | ||
raise | ||
return | ||
end | ||
|
||
retries = retries + 1 | ||
if retries == (@retry_attempts + 1) | ||
This comment has been minimized.
Sorry, something went wrong.
jasonrosendale
|
||
puts "Crossed #{@retry_attempts} attempts. Raising exception ..." | ||
raise | ||
return | ||
else | ||
puts "Caught exception: #{err.message}." | ||
print "Attempt #{retries} of #{@retry_attempts} " | ||
puts "after sleeping for #{@retry_wait_time} seconds ..." | ||
sleep @retry_wait_time | ||
next | ||
end | ||
end | ||
|
||
retries = 0 | ||
|
||
if @throttler && affected_rows > 0 | ||
@throttler.run | ||
|
@@ -108,5 +142,36 @@ def validate | |
error('impossible chunk options (limit must be greater than start)') | ||
end | ||
end | ||
|
||
def retry_on_deadlock(options) | ||
if options.has_key?(:retry_on_deadlock) && | ||
( options[:retry_on_deadlock].is_a?(TrueClass) || | ||
options[:retry_on_deadlock].is_a?(FalseClass) ) | ||
|
||
return options[:retry_on_deadlock] | ||
end | ||
|
||
return true | ||
end | ||
|
||
def retry_attempts(options) | ||
if options.has_key?(:retry_attempts) && | ||
options[:retry_attempts].is_a?(Numeric) | ||
|
||
return options[:retry_attempts] | ||
end | ||
|
||
return 10 | ||
end | ||
|
||
def retry_wait_time(options) | ||
if options.has_key?(:retry_wait_time) && | ||
options[:retry_wait_time].is_a?(Numeric) | ||
|
||
return options[:retry_wait_time] | ||
end | ||
|
||
return 10 | ||
end | ||
end | ||
end |
The
return
doesn't do anything here -- is it there to make it easier to follow the logic branches?