2021-09-04 01:27:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module BulkImports
|
|
|
|
class ExportStatus
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
def initialize(pipeline_tracker, relation)
|
|
|
|
@pipeline_tracker = pipeline_tracker
|
|
|
|
@relation = relation
|
|
|
|
@entity = @pipeline_tracker.entity
|
|
|
|
@configuration = @entity.bulk_import.configuration
|
2021-09-30 23:02:18 +05:30
|
|
|
@client = Clients::HTTP.new(url: @configuration.url, token: @configuration.access_token)
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def started?
|
|
|
|
export_status['status'] == Export::STARTED
|
|
|
|
end
|
|
|
|
|
|
|
|
def failed?
|
|
|
|
export_status['status'] == Export::FAILED
|
|
|
|
end
|
|
|
|
|
|
|
|
def error
|
|
|
|
export_status['error']
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :client, :entity, :relation
|
|
|
|
|
|
|
|
def export_status
|
|
|
|
strong_memoize(:export_status) do
|
2022-05-07 20:08:51 +05:30
|
|
|
status = fetch_export_status
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
relation_export_status = status&.find { |item| item['relation'] == relation }
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
# Consider empty response as failed export
|
2022-06-21 17:19:12 +05:30
|
|
|
raise StandardError, 'Empty relation export status' unless relation_export_status&.present?
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
relation_export_status
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
rescue StandardError => e
|
|
|
|
{ 'status' => Export::FAILED, 'error' => e.message }
|
|
|
|
end
|
|
|
|
|
|
|
|
def fetch_export_status
|
|
|
|
client.get(status_endpoint).parsed_response
|
|
|
|
end
|
|
|
|
|
|
|
|
def status_endpoint
|
2021-11-18 22:05:49 +05:30
|
|
|
File.join(entity.export_relations_url_path, 'status')
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|