debian-mirror-gitlab/lib/bulk_imports/common/pipelines/entity_finisher.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.4 KiB
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
module BulkImports
2021-11-11 11:23:49 +05:30
module Common
2021-04-29 21:17:54 +05:30
module Pipelines
class EntityFinisher
2022-07-16 23:28:13 +05:30
def self.file_extraction_pipeline?
2021-09-04 01:27:46 +05:30
false
end
2021-04-29 21:17:54 +05:30
def initialize(context)
@context = context
2021-09-04 01:27:46 +05:30
@entity = @context.entity
@trackers = @entity.trackers
2021-04-29 21:17:54 +05:30
end
def run
2021-09-04 01:27:46 +05:30
return if entity.finished? || entity.failed?
2021-04-29 21:17:54 +05:30
2021-09-04 01:27:46 +05:30
if all_other_trackers_failed?
entity.fail_op!
else
entity.finish!
end
2021-04-29 21:17:54 +05:30
logger.info(
2023-01-13 00:05:48 +05:30
bulk_import_id: entity.bulk_import_id,
bulk_import_entity_id: entity.id,
bulk_import_entity_type: entity.source_type,
source_full_path: entity.source_full_path,
2021-04-29 21:17:54 +05:30
pipeline_class: self.class.name,
2022-11-25 23:54:43 +05:30
message: "Entity #{entity.status_name}",
2023-01-13 00:05:48 +05:30
source_version: entity.bulk_import.source_version_info.to_s,
2022-11-25 23:54:43 +05:30
importer: 'gitlab_migration'
2021-04-29 21:17:54 +05:30
)
2022-06-21 17:19:12 +05:30
context.portable.try(:after_import)
2021-04-29 21:17:54 +05:30
end
private
2021-09-04 01:27:46 +05:30
attr_reader :context, :entity, :trackers
2021-04-29 21:17:54 +05:30
def logger
@logger ||= Gitlab::Import::Logger.build
end
2021-09-04 01:27:46 +05:30
def all_other_trackers_failed?
trackers.where.not(relation: self.class.name).all? { |tracker| tracker.failed? } # rubocop: disable CodeReuse/ActiveRecord
end
2021-04-29 21:17:54 +05:30
end
end
end
end