debian-mirror-gitlab/lib/gitlab/sidekiq_config/cli_methods.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
2.1 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'yaml'
require 'set'
# These methods are called by `sidekiq-cluster`, which runs outside of
# the bundler/Rails context, so we cannot use any gem or Rails methods.
module Gitlab
module SidekiqConfig
module CliMethods
# The methods in this module are used as module methods
# rubocop:disable Gitlab/ModuleWithInstanceVariables
extend self
2021-04-29 21:17:54 +05:30
# The file names are misleading. Those files contain the metadata of the
# workers. They should be renamed to all_workers instead.
# https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/1018
2020-03-13 15:44:24 +05:30
QUEUE_CONFIG_PATHS = begin
result = %w[app/workers/all_queues.yml]
result << 'ee/app/workers/all_queues.yml' if Gitlab.ee?
2021-12-11 22:18:48 +05:30
result << 'jh/app/workers/all_queues.yml' if Gitlab.jh?
2020-03-13 15:44:24 +05:30
result
end.freeze
2021-04-29 21:17:54 +05:30
def worker_metadatas(rails_path = Rails.root.to_s)
@worker_metadatas ||= {}
2020-03-13 15:44:24 +05:30
2021-04-29 21:17:54 +05:30
@worker_metadatas[rails_path] ||= QUEUE_CONFIG_PATHS.flat_map do |path|
2020-03-13 15:44:24 +05:30
full_path = File.join(rails_path, path)
File.exist?(full_path) ? YAML.load_file(full_path) : []
end
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
def worker_queues(rails_path = Rails.root.to_s)
2021-04-29 21:17:54 +05:30
worker_names(worker_metadatas(rails_path))
2020-03-13 15:44:24 +05:30
end
def 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}:/)]
end
end
2021-04-29 21:17:54 +05:30
def query_queues(query_string, worker_metadatas)
matcher = SidekiqConfig::WorkerMatcher.new(query_string)
selected_metadatas = worker_metadatas.select do |worker_metadata|
matcher.match?(worker_metadata)
end
worker_names(selected_metadatas)
2020-03-13 15:44:24 +05:30
end
def clear_memoization!
2023-03-17 16:20:25 +05:30
if instance_variable_defined?(:@worker_metadatas)
remove_instance_variable(:@worker_metadatas)
2020-03-13 15:44:24 +05:30
end
end
private
def worker_names(workers)
2020-05-24 23:13:21 +05:30
workers.map { |queue| queue[:name] }
2020-03-13 15:44:24 +05:30
end
end
end
end