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

repository_import_worker.rb « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 861ea5bf896113ff365ec1583ae8305ea42f8523 (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
53
54
55
56
# frozen_string_literal: true

class RepositoryImportWorker
  include ApplicationWorker
  include ExceptionBacktrace
  include ProjectStartImport
  include ProjectImportOptions

  # Whitelist this job from Gitlab::SidekiqDaemon::MemoryKiller
  # [TODO] statistic the better value. Maybe staging server is a good test environment?
  # The value 50 means: contribute 50K rss increase per second. This is estimated from: 15M RSS increase when import running for 300 seconds.
  sidekiq_options memory_killer_memory_growth_kb: 50, memory_killer_max_memory_growth_kb: 300_000


  def perform(project_id)
    @project = Project.find(project_id)

    return unless start_import

    Gitlab::Metrics.add_event(:import_repository)

    service = Projects::ImportService.new(project, project.creator)
    result = service.execute

    # Some importers may perform their work asynchronously. In this case it's up
    # to those importers to mark the import process as complete.
    return if service.async?

    if result[:status] == :error
      fail_import(result[:message]) if template_import?

      raise result[:message]
    end

    project.after_import
  end

  private

  attr_reader :project

  def start_import
    return true if start(project.import_state)

    Rails.logger.info("Project #{project.full_path} was in inconsistent state (#{project.import_status}) while importing.") # rubocop:disable Gitlab/RailsLogger
    false
  end

  def fail_import(message)
    project.import_state.mark_as_failed(message)
  end

  def template_import?
    project.gitlab_project_import?
  end
end