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

50 lines
1.2 KiB
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
module BulkImports
module Groups
module Pipelines
class EntityFinisher
2021-09-04 01:27:46 +05:30
def self.ndjson_pipeline?
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
)
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