lib/updateagent/updateagent.rb in onebody-updateagent-0.6.4 vs lib/updateagent/updateagent.rb in onebody-updateagent-0.6.5

- old
+ new

@@ -125,12 +125,25 @@ # use ActiveResource to create/update records on remote end def push @errors = [] puts 'Updating remote end...' index = 0 + retries = 10 print "#{resource.name} 0/0\r"; STDOUT.flush (@create + @update).each_slice(MAX_TO_BATCH_AT_A_TIME) do |records| - response = resource.post(:batch, {}, {:options => @options['remote_options'], :records => records}.to_xml) + begin + xml = {:options => @options['remote_options'], :records => records}.to_xml + response = resource.post(:batch, {}, xml) + rescue ActiveResource::TimeoutError + retries -= 1 + if retries > 0 + puts "ActiveResource::TimeoutError with xml:\n#{xml}\n\nwill retry #{retries} more time(s) after 10 seconds..." + sleep 10 + retry + else + raise + end + end statuses = Hash.from_xml(response.body)['objects'] statuses.each do |status| record = data_by_id[status['legacy_id'].to_i] record['id'] = status['id'] record['name'] = status['name']