debian-mirror-gitlab/app/workers/repository_import_worker.rb

45 lines
1.1 KiB
Ruby
Raw Normal View History

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-03-17 18:26:18 +05:30
project = Project.find(project_id)
2015-04-26 12:48:37 +05:30
2018-03-17 18:26:18 +05:30
return unless start_import(project)
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
fail_import(project, result[:message]) if project.gitlab_project_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-03-17 18:26:18 +05:30
def start_import(project)
return true if start(project)
Rails.logger.info("Project #{project.full_path} was in inconsistent state (#{project.import_status}) while importing.")
false
end
2017-09-10 17:25:29 +05:30
def fail_import(project, message)
project.mark_import_as_failed(message)
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
end