1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# frozen_string_literal: true
module Gitlab
module ImportExport
module Project
class TreeSaver
include DurationMeasuring
attr_reader :full_path
def initialize(project:, current_user:, shared:, params: {}, logger: Gitlab::Import::Logger)
@params = params
@project = project
@current_user = current_user
@shared = shared
@logger = logger
end
def save
with_duration_measuring do
stream_export
true
end
rescue StandardError => e
@shared.error(e)
false
ensure
json_writer&.close
end
private
def stream_export
on_retry = proc do |exception, try, elapsed_time, next_interval|
@logger.info(
message: "Project export retry triggered from streaming",
'error.class': exception.class,
'error.message': exception.message,
try_count: try,
elapsed_time_s: elapsed_time,
wait_to_retry_s: next_interval,
project_name: @project.name,
project_id: @project.id
)
end
serializer = ImportExport::Json::StreamingSerializer.new(
exportable,
reader.project_tree,
json_writer,
exportable_path: "project"
)
Retriable.retriable(on: Net::OpenTimeout, on_retry: on_retry) do
serializer.execute
end
end
def reader
@reader ||= Gitlab::ImportExport::Reader.new(shared: @shared)
end
def exportable
@project.present(**exportable_params)
end
def exportable_params
params = {
presenter_class: presenter_class,
current_user: @current_user
}
params[:override_description] = @params[:description] if @params[:description].present?
params
end
def presenter_class
Projects::ImportExport::ProjectExportPresenter
end
def json_writer
@json_writer ||= begin
if ::Feature.enabled?(:project_export_as_ndjson, @project.namespace)
full_path = File.join(@shared.export_path, 'tree')
Gitlab::ImportExport::Json::NdjsonWriter.new(full_path)
else
full_path = File.join(@shared.export_path, ImportExport.project_filename)
Gitlab::ImportExport::Json::LegacyWriter.new(full_path, allowed_path: 'project')
end
end
end
end
end
end
end
|