BUGFIX: don't leak out a transaction if fails
This commit is contained in:
parent
f71c8bb533
commit
9fc3a335cc
1 changed files with 14 additions and 8 deletions
|
@ -188,7 +188,10 @@ module Jobs
|
|||
parameter_markers = fields.map {|x| "?"}.join(',')
|
||||
sql_stmt = "INSERT INTO #{table_name} (#{fields.join(',')}) VALUES (#{parameter_markers})"
|
||||
|
||||
in_tran = false
|
||||
begin
|
||||
User.exec_sql("BEGIN TRANSACTION") unless Rails.env.test?
|
||||
in_tran = true
|
||||
i = 0
|
||||
rows.each do |row|
|
||||
if i % batch_size == 0 && i > 0
|
||||
|
@ -198,6 +201,9 @@ module Jobs
|
|||
i += 1
|
||||
end
|
||||
User.exec_sql("COMMIT") unless Rails.env.test?
|
||||
rescue
|
||||
User.exec_sql("ROLLBACK") if in_tran
|
||||
end
|
||||
|
||||
true
|
||||
else
|
||||
|
|
Reference in a new issue