debian-mirror-gitlab/app/workers/bulk_imports/entity_worker.rb

60 lines
1.4 KiB
Ruby
Raw Normal View History

2021-03-08 18:12:59 +05:30
# frozen_string_literal: true
module BulkImports
class EntityWorker # rubocop:disable Scalability/IdempotentWorker
include ApplicationWorker
2021-10-27 15:23:28 +05:30
data_consistency :always
2021-03-08 18:12:59 +05:30
feature_category :importers
2021-06-08 01:23:25 +05:30
tags :exclude_from_kubernetes
2021-03-08 18:12:59 +05:30
sidekiq_options retry: false, dead: false
worker_has_external_dependencies!
2021-04-29 21:17:54 +05:30
def perform(entity_id, current_stage = nil)
return if stage_running?(entity_id, current_stage)
logger.info(
worker: self.class.name,
entity_id: entity_id,
current_stage: current_stage
)
next_pipeline_trackers_for(entity_id).each do |pipeline_tracker|
BulkImports::PipelineWorker.perform_async(
pipeline_tracker.id,
pipeline_tracker.stage,
entity_id
)
end
2021-06-08 01:23:25 +05:30
rescue StandardError => e
2021-04-29 21:17:54 +05:30
logger.error(
worker: self.class.name,
entity_id: entity_id,
current_stage: current_stage,
error_message: e.message
)
Gitlab::ErrorTracking.track_exception(e, entity_id: entity_id)
end
2021-03-08 18:12:59 +05:30
2021-04-29 21:17:54 +05:30
private
2021-03-08 18:12:59 +05:30
2021-04-29 21:17:54 +05:30
def stage_running?(entity_id, stage)
return unless stage
2021-03-11 19:13:27 +05:30
2021-04-29 21:17:54 +05:30
BulkImports::Tracker.stage_running?(entity_id, stage)
end
2021-03-11 19:13:27 +05:30
2021-04-29 21:17:54 +05:30
def next_pipeline_trackers_for(entity_id)
BulkImports::Tracker.next_pipeline_trackers_for(entity_id)
end
2021-03-11 19:13:27 +05:30
2021-04-29 21:17:54 +05:30
def logger
@logger ||= Gitlab::Import::Logger.build
2021-03-08 18:12:59 +05:30
end
end
end