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

67 lines
1.9 KiB
Ruby
Raw Normal View History

2018-11-08 19:23:39 +05:30
# frozen_string_literal: true
2020-04-08 14:13:33 +05:30
class RepositoryImportWorker # rubocop:disable Scalability/IdempotentWorker
2018-03-17 18:26:18 +05:30
include ApplicationWorker
include ExceptionBacktrace
include ProjectStartImport
2015-04-26 12:48:37 +05:30
2019-12-21 20:55:43 +05:30
feature_category :importers
2019-12-26 22:10:19 +05:30
worker_has_external_dependencies!
2021-01-03 14:25:43 +05:30
# Do not retry on Import/Export until https://gitlab.com/gitlab-org/gitlab/-/issues/16812 is solved.
sidekiq_options retry: false, dead: false
2020-07-28 23:09:34 +05:30
sidekiq_options status_expiration: Gitlab::Import::StuckImportJob::IMPORT_JOBS_EXPIRATION
2019-12-21 20:55:43 +05:30
# technical debt: https://gitlab.com/gitlab-org/gitlab/issues/33991
sidekiq_options memory_killer_memory_growth_kb: ENV.fetch('MEMORY_KILLER_REPOSITORY_IMPORT_WORKER_MEMORY_GROWTH_KB', 50).to_i
sidekiq_options memory_killer_max_memory_growth_kb: ENV.fetch('MEMORY_KILLER_REPOSITORY_IMPORT_WORKER_MAX_MEMORY_GROWTH_KB', 300_000).to_i
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
2020-06-23 00:09:42 +05:30
Gitlab::Import::Logger.info(
message: 'Project was in inconsistent state while importing',
project_full_path: project.full_path,
project_import_status: project.import_status
)
2018-03-17 18:26:18 +05:30
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
2019-12-04 20:38:33 +05:30
RepositoryImportWorker.prepend_if_ee('EE::RepositoryImportWorker')