2021-05-11 15:10:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module BulkImports
|
|
|
|
class ExportRequestWorker
|
|
|
|
include ApplicationWorker
|
|
|
|
|
2021-07-21 12:09:35 +00:00
|
|
|
data_consistency :always
|
|
|
|
|
2021-05-11 15:10:20 +00:00
|
|
|
idempotent!
|
|
|
|
worker_has_external_dependencies!
|
|
|
|
feature_category :importers
|
|
|
|
|
|
|
|
def perform(entity_id)
|
|
|
|
entity = BulkImports::Entity.find(entity_id)
|
|
|
|
|
|
|
|
request_export(entity)
|
2022-03-14 09:08:52 +00:00
|
|
|
rescue BulkImports::NetworkError => e
|
|
|
|
log_export_failure(e, entity)
|
|
|
|
|
|
|
|
entity.fail_op!
|
2021-05-11 15:10:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def request_export(entity)
|
2021-09-27 18:12:38 +00:00
|
|
|
http_client(entity.bulk_import.configuration).post(entity.export_relations_url_path)
|
2021-05-11 15:10:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def http_client(configuration)
|
2021-06-11 15:09:58 +00:00
|
|
|
@client ||= Clients::HTTP.new(
|
2021-07-08 12:08:30 +00:00
|
|
|
url: configuration.url,
|
2021-05-11 15:10:20 +00:00
|
|
|
token: configuration.access_token
|
|
|
|
)
|
|
|
|
end
|
2022-03-14 09:08:52 +00:00
|
|
|
|
|
|
|
def log_export_failure(exception, entity)
|
|
|
|
attributes = {
|
|
|
|
bulk_import_entity_id: entity.id,
|
|
|
|
pipeline_class: 'ExportRequestWorker',
|
|
|
|
exception_class: exception.class.to_s,
|
|
|
|
exception_message: exception.message.truncate(255),
|
|
|
|
correlation_id_value: Labkit::Correlation::CorrelationId.current_or_new_id
|
|
|
|
}
|
|
|
|
|
2022-04-20 00:09:27 +00:00
|
|
|
Gitlab::Import::Logger.error(
|
|
|
|
structured_payload(
|
|
|
|
attributes.merge(
|
|
|
|
bulk_import_id: entity.bulk_import.id,
|
|
|
|
bulk_import_entity_type: entity.source_type
|
|
|
|
)
|
2022-03-14 09:08:52 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
BulkImports::Failure.create(attributes)
|
|
|
|
end
|
2021-05-11 15:10:20 +00:00
|
|
|
end
|
|
|
|
end
|