2021-05-27 14:10:52 -04:00
|
|
|
# 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-07-08 08:08:30 -04:00
|
|
|
@client = Clients::HTTP.new(url: @configuration.url, token: @configuration.access_token)
|
2021-05-27 14:10:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def started?
|
2022-05-27 11:08:25 -04:00
|
|
|
!empty? && export_status['status'] == Export::STARTED
|
2021-05-27 14:10:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def failed?
|
2022-05-27 11:08:25 -04:00
|
|
|
!empty? && export_status['status'] == Export::FAILED
|
|
|
|
end
|
|
|
|
|
|
|
|
def empty?
|
|
|
|
export_status.nil?
|
2021-05-27 14:10:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def error
|
|
|
|
export_status['error']
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :client, :entity, :relation
|
|
|
|
|
|
|
|
def export_status
|
|
|
|
strong_memoize(:export_status) do
|
2022-05-27 11:08:25 -04:00
|
|
|
fetch_export_status&.find { |item| item['relation'] == relation }
|
2021-05-27 14:10:52 -04:00
|
|
|
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-09-27 14:12:38 -04:00
|
|
|
File.join(entity.export_relations_url_path, 'status')
|
2021-05-27 14:10:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|