blob: 723359aa438a72746365f82f80dd4db6a86614ec (
plain)
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
|
# frozen_string_literal: true
module BulkImports
module Common
module Pipelines
class EntityFinisher
def self.file_extraction_pipeline?
false
end
def initialize(context)
@context = context
@entity = @context.entity
@trackers = @entity.trackers
end
def run
return if entity.finished? || entity.failed?
if all_other_trackers_failed?
entity.fail_op!
else
entity.finish!
end
logger.info(
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,
pipeline_class: self.class.name,
message: "Entity #{entity.status_name}",
source_version: entity.bulk_import.source_version_info.to_s
)
::BulkImports::FinishProjectImportWorker.perform_async(entity.project_id) if entity.project?
end
private
attr_reader :context, :entity, :trackers
def logger
@logger ||= Logger.build
end
def all_other_trackers_failed?
trackers.where.not(relation: self.class.name).all? { |tracker| tracker.failed? } # rubocop: disable CodeReuse/ActiveRecord
end
end
end
end
end
|