Commit 8c034072 authored by Linjie Zhang's avatar Linjie Zhang

Add JH config for sidekiq_queues

parent 99c7c140
...@@ -8,6 +8,7 @@ module Gitlab ...@@ -8,6 +8,7 @@ module Gitlab
EE_QUEUE_CONFIG_PATH = 'ee/app/workers/all_queues.yml' EE_QUEUE_CONFIG_PATH = 'ee/app/workers/all_queues.yml'
JH_QUEUE_CONFIG_PATH = 'jh/app/workers/all_queues.yml' JH_QUEUE_CONFIG_PATH = 'jh/app/workers/all_queues.yml'
SIDEKIQ_QUEUES_PATH = 'config/sidekiq_queues.yml' SIDEKIQ_QUEUES_PATH = 'config/sidekiq_queues.yml'
JH_SIDEKIQ_QUEUES_PATH = 'jh/config/sidekiq_queues.yml'
QUEUE_CONFIG_PATHS = [ QUEUE_CONFIG_PATHS = [
FOSS_QUEUE_CONFIG_PATH, FOSS_QUEUE_CONFIG_PATH,
...@@ -48,7 +49,14 @@ module Gitlab ...@@ -48,7 +49,14 @@ module Gitlab
def config_queues def config_queues
@config_queues ||= begin @config_queues ||= begin
config = YAML.load_file(Rails.root.join(SIDEKIQ_QUEUES_PATH)) config = YAML.load_file(Rails.root.join(SIDEKIQ_QUEUES_PATH))
config[:queues].map(&:first) queues = config[:queues].map(&:first)
if Gitlab.jh? && File.exist?(JH_SIDEKIQ_QUEUES_PATH)
jh_config = YAML.load_file(JH_SIDEKIQ_QUEUES_PATH)
queues += jh_config[:queues].map(&:first)
end
queues
end end
end end
...@@ -97,16 +105,17 @@ module Gitlab ...@@ -97,16 +105,17 @@ module Gitlab
Gitlab.jh? && File.exist?(JH_QUEUE_CONFIG_PATH) && jh_workers != YAML.load_file(JH_QUEUE_CONFIG_PATH) Gitlab.jh? && File.exist?(JH_QUEUE_CONFIG_PATH) && jh_workers != YAML.load_file(JH_QUEUE_CONFIG_PATH)
end end
def queues_for_sidekiq_queues_yml def queues_for_sidekiq_queues_yml(jh: false)
namespaces_with_equal_weights = namespaces_with_equal_weights =
workers workers
.select { |worker| worker.jh? == jh }
.group_by(&:queue_namespace) .group_by(&:queue_namespace)
.map(&:last) .map(&:last)
.select { |workers| workers.map(&:get_weight).uniq.count == 1 } .select { |workers| workers.map(&:get_weight).uniq.count == 1 }
.map(&:first) .map(&:first)
namespaces = namespaces_with_equal_weights.map(&:queue_namespace).to_set namespaces = namespaces_with_equal_weights.map(&:queue_namespace).to_set
remaining_queues = workers.reject { |worker| namespaces.include?(worker.queue_namespace) } remaining_queues = workers.select { |worker| worker.jh? == jh }.reject { |worker| namespaces.include?(worker.queue_namespace) }
(namespaces_with_equal_weights.map(&:namespace_and_weight) + (namespaces_with_equal_weights.map(&:namespace_and_weight) +
remaining_queues.map(&:queue_and_weight)).sort remaining_queues.map(&:queue_and_weight)).sort
...@@ -116,7 +125,12 @@ module Gitlab ...@@ -116,7 +125,12 @@ module Gitlab
def sidekiq_queues_yml_outdated? def sidekiq_queues_yml_outdated?
config_queues = YAML.load_file(SIDEKIQ_QUEUES_PATH)[:queues] config_queues = YAML.load_file(SIDEKIQ_QUEUES_PATH)[:queues]
queues_for_sidekiq_queues_yml != config_queues if Gitlab.jh? && File.exist?(JH_SIDEKIQ_QUEUES_PATH)
jh_config_queues = YAML.load_file(JH_SIDEKIQ_QUEUES_PATH)[:queues]
queues_for_sidekiq_queues_yml != config_queues || queues_for_sidekiq_queues_yml(jh: true) != jh_config_queues
else
queues_for_sidekiq_queues_yml != config_queues
end
end end
# Returns a hash of worker class name => mapped queue name # Returns a hash of worker class name => mapped queue name
......
...@@ -100,6 +100,11 @@ namespace :gitlab do ...@@ -100,6 +100,11 @@ namespace :gitlab do
queues_and_weights = Gitlab::SidekiqConfig.queues_for_sidekiq_queues_yml queues_and_weights = Gitlab::SidekiqConfig.queues_for_sidekiq_queues_yml
write_yaml(Gitlab::SidekiqConfig::SIDEKIQ_QUEUES_PATH, banner, queues: queues_and_weights) write_yaml(Gitlab::SidekiqConfig::SIDEKIQ_QUEUES_PATH, banner, queues: queues_and_weights)
if Gitlab.jh?
jh_quesues_and_weights = Gitlab::SidekiqConfig.queues_for_sidekiq_queues_yml(jh: true)
write_yaml(Gitlab::SidekiqConfig::JH_SIDEKIQ_QUEUES_PATH, banner, queues: jh_quesues_and_weights)
end
end end
desc 'GitLab | Sidekiq | Validate that sidekiq_queues.yml matches worker definitions' desc 'GitLab | Sidekiq | Validate that sidekiq_queues.yml matches worker definitions'
...@@ -113,6 +118,7 @@ namespace :gitlab do ...@@ -113,6 +118,7 @@ namespace :gitlab do
Then commit and push the changes from: Then commit and push the changes from:
- #{Gitlab::SidekiqConfig::SIDEKIQ_QUEUES_PATH} - #{Gitlab::SidekiqConfig::SIDEKIQ_QUEUES_PATH}
#{"- " + Gitlab::SidekiqConfig::JH_SIDEKIQ_QUEUES_PATH if Gitlab.jh?}
MSG MSG
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment