Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-15 21:08:34 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-15 21:08:34 +0300
commit571d993b49313dd806bd3f6af16d36c26d9d28ca (patch)
tree06bd12c4b56b97881aef8a00d4d46698de1eb63f /lib/gitlab/sidekiq_config
parent9044365a91112d426fbbfba07eca595652bbe2df (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/sidekiq_config')
-rw-r--r--lib/gitlab/sidekiq_config/cli_methods.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/gitlab/sidekiq_config/cli_methods.rb b/lib/gitlab/sidekiq_config/cli_methods.rb
new file mode 100644
index 00000000000..1ce46289e81
--- /dev/null
+++ b/lib/gitlab/sidekiq_config/cli_methods.rb
@@ -0,0 +1,43 @@
+# 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
+
+ QUEUE_CONFIG_PATHS = begin
+ result = %w[app/workers/all_queues.yml]
+ result << 'ee/app/workers/all_queues.yml' if Gitlab.ee?
+ result
+ end.freeze
+
+ def 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) : []
+ end
+ 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
+ # rubocop:enable Gitlab/ModuleWithInstanceVariables
+ end
+ end
+end