2018-11-08 19:23:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
class RepositoryImportWorker
|
2018-03-17 18:26:18 +05:30
|
|
|
include ApplicationWorker
|
|
|
|
include ExceptionBacktrace
|
|
|
|
include ProjectStartImport
|
|
|
|
include ProjectImportOptions
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
def perform(project_id)
|
2018-11-18 11:00:15 +05:30
|
|
|
@project = Project.find(project_id)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
return unless start_import
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
Gitlab::Metrics.add_event(:import_repository)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
service = Projects::ImportService.new(project, project.creator)
|
|
|
|
result = service.execute
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
# 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?
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
if result[:status] == :error
|
2018-11-18 11:00:15 +05:30
|
|
|
fail_import(result[:message]) if template_import?
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
raise result[:message]
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
project.after_import
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
attr_reader :project
|
|
|
|
|
|
|
|
def start_import
|
2019-02-15 15:39:39 +05:30
|
|
|
return true if start(project.import_state)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
Rails.logger.info("Project #{project.full_path} was in inconsistent state (#{project.import_status}) while importing.")
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
def fail_import(message)
|
2019-02-15 15:39:39 +05:30
|
|
|
project.import_state.mark_as_failed(message)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
def template_import?
|
|
|
|
project.gitlab_project_import?
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|