summaryrefslogtreecommitdiff
path: root/app/workers/gitlab/github_import/stage/finish_import_worker.rb
blob: f909d7e2f34791580bba479153260e01ce7782b8 (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
# frozen_string_literal: true

module Gitlab
  module GithubImport
    module Stage
      class FinishImportWorker # rubocop:disable Scalability/IdempotentWorker
        include ApplicationWorker

        sidekiq_options retry: 3
        include GithubImport::Queue
        include StageMethods

        # technical debt: https://gitlab.com/gitlab-org/gitlab/issues/33991
        sidekiq_options memory_killer_memory_growth_kb: ENV.fetch('MEMORY_KILLER_FINISH_IMPORT_WORKER_MEMORY_GROWTH_KB', 50).to_i
        sidekiq_options memory_killer_max_memory_growth_kb: ENV.fetch('MEMORY_KILLER_FINISH_IMPORT_WORKER_MAX_MEMORY_GROWTH_KB', 200_000).to_i

        # project - An instance of Project.
        def import(_, project)
          project.after_import
          report_import_time(project)
        end

        def report_import_time(project)
          duration = Time.zone.now - project.created_at

          histogram.observe({ project: project.full_path }, duration)
          counter.increment

          info(
            project.id,
            message: "GitHub project import finished",
            duration_s: duration.round(2),
            object_counts: ::Gitlab::GithubImport::ObjectCounter.summary(project)
          )
        end

        def histogram
          @histogram ||= Gitlab::Metrics.histogram(
            :github_importer_total_duration_seconds,
            'Total time spent importing GitHub projects, in seconds'
          )
        end

        def counter
          @counter ||= Gitlab::Metrics.counter(
            :github_importer_imported_projects,
            'The number of imported GitHub projects'
          )
        end
      end
    end
  end
end