2018-03-17 18:26:18 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module GithubImport
|
|
|
|
module Stage
|
2020-04-08 14:13:33 +05:30
|
|
|
class ImportRepositoryWorker # rubocop:disable Scalability/IdempotentWorker
|
2018-03-17 18:26:18 +05:30
|
|
|
include ApplicationWorker
|
|
|
|
include GithubImport::Queue
|
|
|
|
include StageMethods
|
|
|
|
|
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_IMPORT_REPOSITORY_WORKER_MEMORY_GROWTH_KB', 50).to_i
|
|
|
|
sidekiq_options memory_killer_max_memory_growth_kb: ENV.fetch('MEMORY_KILLER_IMPORT_REPOSITORY_WORKER_MAX_MEMORY_GROWTH_KB', 300_000).to_i
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
# client - An instance of Gitlab::GithubImport::Client.
|
|
|
|
# project - An instance of Project.
|
|
|
|
def import(client, project)
|
|
|
|
# In extreme cases it's possible for a clone to take more than the
|
|
|
|
# import job expiration time. To work around this we schedule a
|
|
|
|
# separate job that will periodically run and refresh the import
|
|
|
|
# expiration time.
|
|
|
|
RefreshImportJidWorker.perform_in_the_future(project.id, jid)
|
|
|
|
|
|
|
|
importer = Importer::RepositoryImporter.new(project, client)
|
|
|
|
|
|
|
|
return unless importer.execute
|
|
|
|
|
|
|
|
counter.increment
|
|
|
|
|
|
|
|
ImportBaseDataWorker.perform_async(project.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def counter
|
|
|
|
Gitlab::Metrics.counter(
|
|
|
|
:github_importer_imported_repositories,
|
|
|
|
'The number of imported GitHub repositories'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|