From 4825bf7e0247aae3524ac1515730a0c21d31c611 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 31 Jan 2014 11:40:25 +1100 Subject: [PATCH] REFACTOR: clean up mechanism --- app/jobs/regular/importer.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/jobs/regular/importer.rb b/app/jobs/regular/importer.rb index 458dc6702..9a4d01aa8 100644 --- a/app/jobs/regular/importer.rb +++ b/app/jobs/regular/importer.rb @@ -190,8 +190,10 @@ module Jobs in_tran = false begin - User.exec_sql("BEGIN TRANSACTION") unless Rails.env.test? - in_tran = true + unless Rails.env.test? + User.exec_sql("BEGIN TRANSACTION") + in_tran = true + end i = 0 rows.each do |row| if i % batch_size == 0 && i > 0 @@ -200,7 +202,7 @@ module Jobs User.exec_sql(sql_stmt, *row) i += 1 end - User.exec_sql("COMMIT") unless Rails.env.test? + User.exec_sql("COMMIT") if in_tran rescue User.exec_sql("ROLLBACK") if in_tran end