2018-06-27 07:23:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-08-12 15:21:47 +00:00
|
|
|
class RepositoryImportWorker
|
2017-11-28 16:08:30 +00:00
|
|
|
include ApplicationWorker
|
2017-08-24 19:24:58 +00:00
|
|
|
include ExceptionBacktrace
|
2017-10-10 09:09:49 +00:00
|
|
|
include ProjectStartImport
|
2017-12-11 11:35:03 +00:00
|
|
|
include ProjectImportOptions
|
2015-02-18 16:00:26 +00:00
|
|
|
|
2016-01-21 18:09:32 +00:00
|
|
|
def perform(project_id)
|
2018-07-20 23:25:10 +00:00
|
|
|
@project = Project.find(project_id)
|
2013-08-12 15:21:47 +00:00
|
|
|
|
2018-07-20 23:25:10 +00:00
|
|
|
return unless start_import
|
2017-06-01 14:27:35 +00:00
|
|
|
|
2018-06-19 17:03:25 +00:00
|
|
|
Gitlab::Metrics.add_event(:import_repository)
|
2016-08-10 21:22:21 +00:00
|
|
|
|
2017-10-13 16:50:36 +00:00
|
|
|
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?
|
|
|
|
|
2018-01-26 09:43:13 +00:00
|
|
|
if result[:status] == :error
|
2018-07-20 23:25:10 +00:00
|
|
|
fail_import(result[:message]) if template_import?
|
2018-01-26 09:43:13 +00:00
|
|
|
|
|
|
|
raise result[:message]
|
|
|
|
end
|
2015-11-11 15:22:51 +00:00
|
|
|
|
2017-10-13 16:50:36 +00:00
|
|
|
project.after_import
|
2017-06-01 14:27:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-07-23 13:25:35 +00:00
|
|
|
attr_reader :project
|
|
|
|
|
2018-07-20 23:25:10 +00:00
|
|
|
def start_import
|
2018-11-27 09:41:27 +00:00
|
|
|
return true if start(project.import_state)
|
2017-08-17 09:00:31 +00:00
|
|
|
|
|
|
|
Rails.logger.info("Project #{project.full_path} was in inconsistent state (#{project.import_status}) while importing.")
|
|
|
|
false
|
|
|
|
end
|
2018-01-26 09:43:13 +00:00
|
|
|
|
2018-07-20 23:25:10 +00:00
|
|
|
def fail_import(message)
|
2018-11-27 09:41:27 +00:00
|
|
|
project.import_state.mark_as_failed(message)
|
2018-01-26 09:43:13 +00:00
|
|
|
end
|
2018-07-20 23:25:10 +00:00
|
|
|
|
|
|
|
def template_import?
|
|
|
|
project.gitlab_project_import?
|
|
|
|
end
|
2014-09-25 22:07:40 +00:00
|
|
|
end
|