2024-09-09 23:14:39 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Migrations::Converters::Base
|
|
|
|
class ParallelJob
|
|
|
|
def initialize(step)
|
|
|
|
@step = step
|
2024-11-20 06:54:37 +08:00
|
|
|
@tracker = step.tracker
|
2024-09-09 23:14:39 +08:00
|
|
|
|
|
|
|
@offline_connection = ::Migrations::Database::OfflineConnection.new
|
|
|
|
|
|
|
|
::Migrations::ForkManager.after_fork_child do
|
|
|
|
::Migrations::Database::IntermediateDB.setup(@offline_connection)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run(item)
|
2024-11-20 06:54:37 +08:00
|
|
|
@tracker.reset_stats!
|
2024-09-09 23:14:39 +08:00
|
|
|
@offline_connection.clear!
|
|
|
|
|
|
|
|
begin
|
2024-11-20 06:54:37 +08:00
|
|
|
@step.process_item(item)
|
2024-09-09 23:14:39 +08:00
|
|
|
rescue StandardError => e
|
2024-11-20 06:54:37 +08:00
|
|
|
@tracker.log_error("Failed to process item", exception: e, details: item)
|
2024-09-09 23:14:39 +08:00
|
|
|
end
|
|
|
|
|
2024-11-20 06:54:37 +08:00
|
|
|
[@offline_connection.parametrized_insert_statements, @tracker.stats]
|
2024-09-09 23:14:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def cleanup
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|