diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-11-28 17:08:30 +0100 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-12-05 11:59:39 +0100 |
commit | 0b15570e497d3c5c515be59a43b686087b985f5c (patch) | |
tree | 759ba4c5764145345dce24509a5faf65c6476b9e /lib | |
parent | 4ca4b0ff702a68a9aed5da70d9170da410eefafa (diff) | |
download | gitlab-ce-0b15570e497d3c5c515be59a43b686087b985f5c.tar.gz |
Add ApplicationWorker and make every worker include it
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/sidekiq_config.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/gitlab/sidekiq_config.rb b/lib/gitlab/sidekiq_config.rb new file mode 100644 index 00000000000..dc9886732b5 --- /dev/null +++ b/lib/gitlab/sidekiq_config.rb @@ -0,0 +1,50 @@ +require 'yaml' + +module Gitlab + module SidekiqConfig + def self.redis_queues + @redis_queues ||= Sidekiq::Queue.all.map(&:name) + end + + # This method is called by `bin/sidekiq-cluster` in EE, which runs outside + # of bundler/Rails context, so we cannot use any gem or Rails methods. + def self.config_queues(rails_path = Rails.root.to_s) + @config_queues ||= begin + config = YAML.load_file(File.join(rails_path, 'config', 'sidekiq_queues.yml')) + config[:queues].map(&:first) + end + end + + def self.cron_workers + @cron_workers ||= Settings.cron_jobs.map { |job_name, options| options['job_class'].constantize } + end + + def self.workers + @workers ||= find_workers(Rails.root.join('app', 'workers')) + end + + def self.default_queues + [ActionMailer::DeliveryJob.queue_name, 'default'] + end + + def self.worker_queues + @worker_queues ||= (workers.map(&:queue) + default_queues).uniq + end + + def self.find_workers(root) + concerns = root.join('concerns').to_s + + 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', '') + + ns.camelize.constantize + end + + # Skip concerns + workers.select { |w| w < Sidekiq::Worker } + end + end +end |