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.

52 lines
1.2 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(
bulk_import_id: context.bulk_import.id,
bulk_import_entity_id: context.entity.id,
bulk_import_entity_type: context.entity.source_type,
pipeline_class: self.class.name,
2021-09-04 01:27:46 +05:30
message: "Entity #{entity.status_name}"
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