2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
class DetectRepositoryLanguagesWorker
|
|
|
|
include ApplicationWorker
|
|
|
|
include ExceptionBacktrace
|
|
|
|
include ExclusiveLeaseGuard
|
|
|
|
|
|
|
|
sidekiq_options retry: 1
|
2019-12-21 20:55:43 +05:30
|
|
|
feature_category :source_code_management
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
LEASE_TIMEOUT = 300
|
|
|
|
|
|
|
|
attr_reader :project
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2019-09-04 21:01:54 +05:30
|
|
|
def perform(project_id, user_id = nil)
|
2018-11-18 11:00:15 +05:30
|
|
|
@project = Project.find_by(id: project_id)
|
2019-09-04 21:01:54 +05:30
|
|
|
return unless project
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
try_obtain_lease do
|
2019-09-04 21:01:54 +05:30
|
|
|
::Projects::DetectRepositoryLanguagesService.new(project).execute
|
2018-11-18 11:00:15 +05:30
|
|
|
end
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def lease_timeout
|
|
|
|
LEASE_TIMEOUT
|
|
|
|
end
|
|
|
|
|
|
|
|
def lease_key
|
|
|
|
"gitlab:detect_repository_languages:#{project.id}"
|
|
|
|
end
|
|
|
|
end
|