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)
|
2017-08-17 09:00:31 +00:00
|
|
|
project = Project.find(project_id)
|
2013-08-12 15:21:47 +00:00
|
|
|
|
2017-08-17 09:00:31 +00:00
|
|
|
return unless start_import(project)
|
2017-06-01 14:27:35 +00:00
|
|
|
|
2016-08-16 14:18:48 +00:00
|
|
|
Gitlab::Metrics.add_event(:import_repository,
|
2017-08-17 09:00:31 +00:00
|
|
|
import_url: project.import_url,
|
|
|
|
path: project.full_path)
|
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
|
|
|
|
fail_import(project, result[:message]) if project.gitlab_project_import?
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-08-17 09:00:31 +00:00
|
|
|
def start_import(project)
|
2017-10-10 09:09:49 +00:00
|
|
|
return true if start(project)
|
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
|
|
|
|
|
|
|
def fail_import(project, message)
|
|
|
|
project.mark_import_as_failed(message)
|
|
|
|
end
|
2014-09-25 22:07:40 +00:00
|
|
|
end
|