REFACTOR: clean up mechanism

This commit is contained in:
Sam 2014-01-31 11:40:25 +11:00
parent 9fc3a335cc
commit 4825bf7e02
1 changed files with 5 additions and 3 deletions

View File

@ -190,8 +190,10 @@ module Jobs
in_tran = false in_tran = false
begin begin
User.exec_sql("BEGIN TRANSACTION") unless Rails.env.test? unless Rails.env.test?
User.exec_sql("BEGIN TRANSACTION")
in_tran = true in_tran = true
end
i = 0 i = 0
rows.each do |row| rows.each do |row|
if i % batch_size == 0 && i > 0 if i % batch_size == 0 && i > 0
@ -200,7 +202,7 @@ module Jobs
User.exec_sql(sql_stmt, *row) User.exec_sql(sql_stmt, *row)
i += 1 i += 1
end end
User.exec_sql("COMMIT") unless Rails.env.test? User.exec_sql("COMMIT") if in_tran
rescue rescue
User.exec_sql("ROLLBACK") if in_tran User.exec_sql("ROLLBACK") if in_tran
end end