summaryrefslogtreecommitdiff
path: root/app/workers/gitlab/jira_import/stage/start_import_worker.rb
blob: 5b36feadbd164ee5e5a218b22a7ee378948ab32e (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
# frozen_string_literal: true

module Gitlab
  module JiraImport
    module Stage
      class StartImportWorker # rubocop:disable Scalability/IdempotentWorker
        include ApplicationWorker
        include ProjectStartImport
        include ProjectImportOptions
        include Gitlab::JiraImport::QueueOptions

        attr_reader :project

        def perform(project_id)
          @project = Project.find_by(id: project_id) # rubocop: disable CodeReuse/ActiveRecord

          return unless start_import

          Gitlab::Import::SetAsyncJid.set_jid(project.latest_jira_import)

          Gitlab::JiraImport::Stage::ImportLabelsWorker.perform_async(project.id)
        end

        private

        def start_import
          return false unless project
          return false unless project.jira_issues_import_feature_flag_enabled?
          return true if start(project.latest_jira_import)

          Gitlab::Import::Logger.info(
            {
              project_id: project.id,
              project_path: project.full_path,
              state: project&.jira_import_status,
              message: 'inconsistent state while importing'
            }
          )
          false
        end
      end
    end
  end
end