Welcome to mirror list, hosted at ThFree Co, Russian Federation.

export_status.rb « bulk_imports « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cae6aad27dae20a61679e989336ea2e39f6a5355 (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
# 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
      @client = Clients::HTTP.new(url: @configuration.url, token: @configuration.access_token)
    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
        status = fetch_export_status

        # Consider empty response as failed export
        raise StandardError, 'Empty export status response' unless status&.present?

        status.find { |item| item['relation'] == relation }
      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
      File.join(entity.export_relations_url_path, 'status')
    end
  end
end