diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-15 21:08:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-15 21:08:34 +0300 |
commit | 571d993b49313dd806bd3f6af16d36c26d9d28ca (patch) | |
tree | 06bd12c4b56b97881aef8a00d4d46698de1eb63f /lib/gitlab/sidekiq_config.rb | |
parent | 9044365a91112d426fbbfba07eca595652bbe2df (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/sidekiq_config.rb')
-rw-r--r-- | lib/gitlab/sidekiq_config.rb | 85 |
1 files changed, 30 insertions, 55 deletions
diff --git a/lib/gitlab/sidekiq_config.rb b/lib/gitlab/sidekiq_config.rb index ffceeb68f20..b246c507e9e 100644 --- a/lib/gitlab/sidekiq_config.rb +++ b/lib/gitlab/sidekiq_config.rb @@ -1,78 +1,53 @@ # frozen_string_literal: true require 'yaml' -require 'set' module Gitlab module SidekiqConfig - QUEUE_CONFIG_PATHS = begin - result = %w[app/workers/all_queues.yml] - result << 'ee/app/workers/all_queues.yml' if Gitlab.ee? - result - end.freeze + class << self + include Gitlab::SidekiqConfig::CliMethods - # This method is called by `ee/bin/sidekiq-cluster` in EE, which runs outside - # of bundler/Rails context, so we cannot use any gem or Rails methods. - def self.worker_queues(rails_path = Rails.root.to_s) - @worker_queues ||= {} - - @worker_queues[rails_path] ||= QUEUE_CONFIG_PATHS.flat_map do |path| - full_path = File.join(rails_path, path) - - File.exist?(full_path) ? YAML.load_file(full_path) : [] + def redis_queues + # Not memoized, because this can change during the life of the application + Sidekiq::Queue.all.map(&:name) end - end - - # This method is called by `ee/bin/sidekiq-cluster` in EE, which runs outside - # of bundler/Rails context, so we cannot use any gem or Rails methods. - def self.expand_queues(queues, all_queues = self.worker_queues) - return [] if queues.empty? - queues_set = all_queues.to_set - - queues.flat_map do |queue| - [queue, *queues_set.grep(/\A#{queue}:/)] + def config_queues + @config_queues ||= begin + config = YAML.load_file(Rails.root.join('config/sidekiq_queues.yml')) + config[:queues].map(&:first) + end end - end - def self.redis_queues - # Not memoized, because this can change during the life of the application - Sidekiq::Queue.all.map(&:name) - end + def cron_workers + @cron_workers ||= Settings.cron_jobs.map { |job_name, options| options['job_class'].constantize } + end - def self.config_queues - @config_queues ||= begin - config = YAML.load_file(Rails.root.join('config/sidekiq_queues.yml')) - config[:queues].map(&:first) + def workers + @workers ||= begin + result = find_workers(Rails.root.join('app', 'workers')) + result.concat(find_workers(Rails.root.join('ee', 'app', 'workers'))) if Gitlab.ee? + result + end end - end - def self.cron_workers - @cron_workers ||= Settings.cron_jobs.map { |job_name, options| options['job_class'].constantize } - end + private - def self.workers - @workers ||= begin - result = find_workers(Rails.root.join('app', 'workers')) - result.concat(find_workers(Rails.root.join('ee', 'app', 'workers'))) if Gitlab.ee? - result - end - end + def find_workers(root) + concerns = root.join('concerns').to_s - def self.find_workers(root) - concerns = root.join('concerns').to_s + workers = Dir[root.join('**', '*.rb')] + .reject { |path| path.start_with?(concerns) } - workers = Dir[root.join('**', '*.rb')] - .reject { |path| path.start_with?(concerns) } + workers.map! do |path| + ns = Pathname.new(path).relative_path_from(root).to_s.gsub('.rb', '') - workers.map! do |path| - ns = Pathname.new(path).relative_path_from(root).to_s.gsub('.rb', '') + ns.camelize.constantize + end - ns.camelize.constantize + # Skip things that aren't workers + workers.select { |w| w < Sidekiq::Worker } end - - # Skip things that aren't workers - workers.select { |w| w < Sidekiq::Worker } end end end |