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

module Gitlab
  module GithubImport
    module Stage
      class FinishImportWorker
        include Sidekiq::Worker
        include GithubImport::Queue
        include StageMethods

        # 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
          path = project.path_with_namespace

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

          logger.info("GitHub importer finished for #{path} in #{duration.round(2)} seconds")
        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