lib/gamma/importer/replace.rb in gamma-0.1.8 vs lib/gamma/importer/replace.rb in gamma-0.1.9
- old
+ new
@@ -1,13 +1,14 @@
class Gamma::Importer::Replace < Gamma::Importer
BATCH_SIZE = 1000
- def initialize(in_client, out_client, table, apply: false)
+ def initialize(in_client, out_client, table, apply: false, ignore_error: false)
@in_client = in_client
@out_client = out_client
@table = table
@apply = apply
+ @ignore_error = ignore_error
end
def execute
set_foreign_key_off(@out_client)
batch_sync
@@ -68,11 +69,11 @@
EOS
query = query.strip_heredoc
logger.info(query) if ENV["DEBUG"]
if @apply
- @out_client.client.query(query)
+ exec_query(query)
else
logger.info("DRYRUN: #{query}")
end
end
end
@@ -88,11 +89,11 @@
EOS
query = query.strip_heredoc
logger.info(query) if ENV["DEBUG"]
if @apply
- @out_client.client.query(query)
+ exec_query(query)
else
logger.info("DRYRUN: #{query}")
end
end
@@ -116,7 +117,18 @@
else
r[v]
end
"`#{v}` = \"#{@out_client.client.escape(c.to_s)}\""
end.join(",")
+ end
+
+ def exec_query(query)
+ @out_client.client.query(query)
+ rescue => e
+ if @ignore_error
+ logger.error("An ERROR has occurred and ignore it.")
+ logger.error(e)
+ else
+ throw e
+ end
end
end