Module: Gitlab::SidekiqConfig::CliMethods

Extended by:
CliMethods
Included in:
Gitlab::SidekiqConfig, CliMethods
Defined in:
lib/gitlab/sidekiq_config/cli_methods.rb

Constant Summary collapse

QUEUE_CONFIG_PATHS =
begin
  result = %w[app/workers/all_queues.yml]
  result << 'ee/app/workers/all_queues.yml' if Gitlab.ee?
  result
end.freeze
QUERY_OR_OPERATOR =
'|'
QUERY_AND_OPERATOR =
'&'
QUERY_CONCATENATE_OPERATOR =
','
QUERY_TERM_REGEX =
%r{^(\w+)(!?=)([\w:#{QUERY_CONCATENATE_OPERATOR}]+)}.freeze
QUERY_PREDICATES =
{
  feature_category: :to_sym,
  has_external_dependencies: lambda { |value| value == 'true' },
  name: :to_s,
  resource_boundary: :to_sym,
  tags: :to_sym,
  urgency: :to_sym
}.freeze
QueryError =
Class.new(StandardError)
InvalidTerm =
Class.new(QueryError)
UnknownOperator =
Class.new(QueryError)
UnknownPredicate =
Class.new(QueryError)

Instance Method Summary collapse

Instance Method Details

#all_queues(rails_path = Rails.root.to_s) ⇒ Object


40
41
42
43
44
45
46
47
48
# File 'lib/gitlab/sidekiq_config/cli_methods.rb', line 40

def all_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) : []
  end
end

#clear_memoization!Object


69
70
71
72
73
# File 'lib/gitlab/sidekiq_config/cli_methods.rb', line 69

def clear_memoization!
  if instance_variable_defined?('@worker_queues')
    remove_instance_variable('@worker_queues')
  end
end

#expand_queues(queues, all_queues = self.worker_queues) ⇒ Object


55
56
57
58
59
60
61
62
63
# File 'lib/gitlab/sidekiq_config/cli_methods.rb', line 55

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

#query_workers(query_string, queues) ⇒ Object


65
66
67
# File 'lib/gitlab/sidekiq_config/cli_methods.rb', line 65

def query_workers(query_string, queues)
  worker_names(queues.select(&query_string_to_lambda(query_string)))
end

#worker_queues(rails_path = Rails.root.to_s) ⇒ Object

rubocop:enable Gitlab/ModuleWithInstanceVariables


51
52
53
# File 'lib/gitlab/sidekiq_config/cli_methods.rb', line 51

def worker_queues(rails_path = Rails.root.to_s)
  worker_names(all_queues(rails_path))
end