2014-09-02 18:07:02 +05:30
|
|
|
class RepositoryImportWorker
|
2017-09-10 17:25:29 +05:30
|
|
|
ImportError = Class.new(StandardError)
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
include Sidekiq::Worker
|
2016-11-03 12:29:30 +05:30
|
|
|
include DedicatedSidekiqQueue
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
sidekiq_options status_expiration: StuckImportJobsWorker::IMPORT_EXPIRATION
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
attr_accessor :project, :current_user
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
def perform(project_id)
|
|
|
|
@project = Project.find(project_id)
|
|
|
|
@current_user = @project.creator
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
project.import_start
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
Gitlab::Metrics.add_event(:import_repository,
|
|
|
|
import_url: @project.import_url,
|
2017-09-10 17:25:29 +05:30
|
|
|
path: @project.full_path)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
project.update_columns(import_jid: self.jid, import_error: nil)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
result = Projects::ImportService.new(project, current_user).execute
|
2017-09-10 17:25:29 +05:30
|
|
|
raise ImportError, result[:message] if result[:status] == :error
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
project.repository.after_import
|
2015-04-26 12:48:37 +05:30
|
|
|
project.import_finish
|
2017-09-10 17:25:29 +05:30
|
|
|
rescue ImportError => ex
|
|
|
|
fail_import(project, ex.message)
|
|
|
|
raise
|
|
|
|
rescue => ex
|
|
|
|
return unless project
|
|
|
|
|
|
|
|
fail_import(project, ex.message)
|
|
|
|
raise ImportError, "#{ex.class} #{ex.message}"
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
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
|