diff options
Diffstat (limited to 'lib/bulk_imports/common/extractors/ndjson_extractor.rb')
-rw-r--r-- | lib/bulk_imports/common/extractors/ndjson_extractor.rb | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/lib/bulk_imports/common/extractors/ndjson_extractor.rb b/lib/bulk_imports/common/extractors/ndjson_extractor.rb index ecd7c08bd25..04febebff8e 100644 --- a/lib/bulk_imports/common/extractors/ndjson_extractor.rb +++ b/lib/bulk_imports/common/extractors/ndjson_extractor.rb @@ -4,49 +4,47 @@ module BulkImports module Common module Extractors class NdjsonExtractor - include Gitlab::ImportExport::CommandLineUtil - include Gitlab::Utils::StrongMemoize - def initialize(relation:) @relation = relation - @tmp_dir = Dir.mktmpdir + @tmpdir = Dir.mktmpdir end def extract(context) - download_service(tmp_dir, context).execute - decompression_service(tmp_dir).execute - relations = ndjson_reader(tmp_dir).consume_relation('', relation) + download_service(context).execute + decompression_service.execute + + records = ndjson_reader.consume_relation('', relation) - BulkImports::Pipeline::ExtractedData.new(data: relations) + BulkImports::Pipeline::ExtractedData.new(data: records) end - def remove_tmp_dir - FileUtils.remove_entry(tmp_dir) + def remove_tmpdir + FileUtils.remove_entry(tmpdir) if Dir.exist?(tmpdir) end private - attr_reader :relation, :tmp_dir + attr_reader :relation, :tmpdir def filename - @filename ||= "#{relation}.ndjson.gz" + "#{relation}.ndjson.gz" end - def download_service(tmp_dir, context) + def download_service(context) @download_service ||= BulkImports::FileDownloadService.new( configuration: context.configuration, relative_url: context.entity.relation_download_url_path(relation), - dir: tmp_dir, + tmpdir: tmpdir, filename: filename ) end - def decompression_service(tmp_dir) - @decompression_service ||= BulkImports::FileDecompressionService.new(dir: tmp_dir, filename: filename) + def decompression_service + @decompression_service ||= BulkImports::FileDecompressionService.new(tmpdir: tmpdir, filename: filename) end - def ndjson_reader(tmp_dir) - @ndjson_reader ||= Gitlab::ImportExport::Json::NdjsonReader.new(tmp_dir) + def ndjson_reader + @ndjson_reader ||= Gitlab::ImportExport::Json::NdjsonReader.new(tmpdir) end end end |