2018-06-27 07:23:28 +00:00
# frozen_string_literal: true
2020-02-19 18:09:10 +00:00
class RepositoryImportWorker # rubocop:disable Scalability/IdempotentWorker
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
2019-10-18 11:11:44 +00:00
feature_category :importers
2019-10-30 15:14:17 +00:00
worker_has_external_dependencies!
2019-10-18 11:11:44 +00:00
2019-10-15 09:06:09 +00:00
# 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-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
2019-07-10 19:26:47 +00:00
Rails . logger . info ( " Project #{ project . full_path } was in inconsistent state ( #{ project . import_status } ) while importing. " ) # rubocop:disable Gitlab/RailsLogger
2017-08-17 09:00:31 +00:00
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
2019-09-13 13:26:31 +00:00
RepositoryImportWorker . prepend_if_ee ( 'EE::RepositoryImportWorker' )