Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/bulk_imports')
-rw-r--r--app/models/bulk_imports/entity.rb23
-rw-r--r--app/models/bulk_imports/export_status.rb14
-rw-r--r--app/models/bulk_imports/failure.rb20
-rw-r--r--app/models/bulk_imports/tracker.rb2
4 files changed, 54 insertions, 5 deletions
diff --git a/app/models/bulk_imports/entity.rb b/app/models/bulk_imports/entity.rb
index e0a616b5fb4..a2542e669e1 100644
--- a/app/models/bulk_imports/entity.rb
+++ b/app/models/bulk_imports/entity.rb
@@ -116,8 +116,20 @@ class BulkImports::Entity < ApplicationRecord
"/#{pluralized_name}/#{encoded_source_full_path}"
end
+ def base_xid_resource_url_path
+ "/#{pluralized_name}/#{source_xid}"
+ end
+
+ def base_resource_path
+ if source_xid.present?
+ base_xid_resource_url_path
+ else
+ base_resource_url_path
+ end
+ end
+
def export_relations_url_path
- "#{base_resource_url_path}/export_relations"
+ "#{base_resource_path}/export_relations"
end
def relation_download_url_path(relation)
@@ -125,7 +137,7 @@ class BulkImports::Entity < ApplicationRecord
end
def wikis_url_path
- "#{base_resource_url_path}/wikis"
+ "#{base_resource_path}/wikis"
end
def project?
@@ -149,6 +161,13 @@ class BulkImports::Entity < ApplicationRecord
end
def validate_imported_entity_type
+ if project_entity? && !BulkImports::Features.project_migration_enabled?(destination_namespace)
+ errors.add(
+ :base,
+ s_('BulkImport|invalid entity source type')
+ )
+ end
+
if group.present? && project_entity?
errors.add(
:group,
diff --git a/app/models/bulk_imports/export_status.rb b/app/models/bulk_imports/export_status.rb
index 4fea62edb2a..cbd7b189007 100644
--- a/app/models/bulk_imports/export_status.rb
+++ b/app/models/bulk_imports/export_status.rb
@@ -30,14 +30,18 @@ module BulkImports
private
- attr_reader :client, :entity, :relation
+ attr_reader :client, :entity, :relation, :pipeline_tracker
def export_status
strong_memoize(:export_status) do
fetch_export_status&.find { |item| item['relation'] == relation }
+ rescue BulkImports::NetworkError => e
+ raise BulkImports::RetryPipelineError.new(e.message, 2.seconds) if e.retriable?(pipeline_tracker)
+
+ default_error_response(e.message)
+ rescue StandardError => e
+ default_error_response(e.message)
end
- rescue StandardError => e
- { 'status' => Export::FAILED, 'error' => e.message }
end
def fetch_export_status
@@ -47,5 +51,9 @@ module BulkImports
def status_endpoint
File.join(entity.export_relations_url_path, 'status')
end
+
+ def default_error_response(message)
+ { 'status' => Export::FAILED, 'error' => message }
+ end
end
end
diff --git a/app/models/bulk_imports/failure.rb b/app/models/bulk_imports/failure.rb
index a6f7582c3b0..44d16618c77 100644
--- a/app/models/bulk_imports/failure.rb
+++ b/app/models/bulk_imports/failure.rb
@@ -10,4 +10,24 @@ class BulkImports::Failure < ApplicationRecord
optional: false
validates :entity, presence: true
+
+ def relation
+ pipeline_relation || default_relation
+ end
+
+ private
+
+ def pipeline_relation
+ klass = pipeline_class.constantize
+
+ return unless klass.ancestors.include?(BulkImports::Pipeline)
+
+ klass.relation
+ rescue NameError
+ nil
+ end
+
+ def default_relation
+ pipeline_class.demodulize.chomp('Pipeline').underscore
+ end
end
diff --git a/app/models/bulk_imports/tracker.rb b/app/models/bulk_imports/tracker.rb
index fa38b7617d2..357f4629078 100644
--- a/app/models/bulk_imports/tracker.rb
+++ b/app/models/bulk_imports/tracker.rb
@@ -60,6 +60,8 @@ class BulkImports::Tracker < ApplicationRecord
event :retry do
transition started: :enqueued
+ # To avoid errors when retrying a pipeline in case of network errors
+ transition enqueued: :enqueued
end
event :enqueue do