2018-10-22 07:00:50 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-28 16:08:30 +00:00
|
|
|
require 'yaml'
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module SidekiqConfig
|
2020-01-15 18:08:34 +00:00
|
|
|
class << self
|
|
|
|
include Gitlab::SidekiqConfig::CliMethods
|
2018-11-19 21:29:19 +00:00
|
|
|
|
2020-01-15 18:08:34 +00:00
|
|
|
def redis_queues
|
|
|
|
# Not memoized, because this can change during the life of the application
|
|
|
|
Sidekiq::Queue.all.map(&:name)
|
2018-11-19 21:29:19 +00:00
|
|
|
end
|
2017-11-28 16:16:50 +00:00
|
|
|
|
2020-01-15 18:08:34 +00:00
|
|
|
def config_queues
|
|
|
|
@config_queues ||= begin
|
|
|
|
config = YAML.load_file(Rails.root.join('config/sidekiq_queues.yml'))
|
|
|
|
config[:queues].map(&:first)
|
|
|
|
end
|
2017-11-28 16:16:50 +00:00
|
|
|
end
|
|
|
|
|
2020-01-15 18:08:34 +00:00
|
|
|
def cron_workers
|
|
|
|
@cron_workers ||= Settings.cron_jobs.map { |job_name, options| options['job_class'].constantize }
|
|
|
|
end
|
2017-11-28 16:16:50 +00:00
|
|
|
|
2020-01-15 18:08:34 +00:00
|
|
|
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
|
2017-11-28 16:08:30 +00:00
|
|
|
end
|
|
|
|
|
2020-01-15 18:08:34 +00:00
|
|
|
private
|
2017-11-28 16:08:30 +00:00
|
|
|
|
2020-01-15 18:08:34 +00:00
|
|
|
def find_workers(root)
|
|
|
|
concerns = root.join('concerns').to_s
|
2017-11-28 16:08:30 +00:00
|
|
|
|
2020-01-15 18:08:34 +00:00
|
|
|
workers = Dir[root.join('**', '*.rb')]
|
|
|
|
.reject { |path| path.start_with?(concerns) }
|
2017-11-28 16:08:30 +00:00
|
|
|
|
2020-01-15 18:08:34 +00:00
|
|
|
workers.map! do |path|
|
|
|
|
ns = Pathname.new(path).relative_path_from(root).to_s.gsub('.rb', '')
|
2017-11-28 16:08:30 +00:00
|
|
|
|
2020-01-15 18:08:34 +00:00
|
|
|
ns.camelize.constantize
|
|
|
|
end
|
2017-11-28 16:08:30 +00:00
|
|
|
|
2020-01-15 18:08:34 +00:00
|
|
|
# Skip things that aren't workers
|
|
|
|
workers.select { |w| w < Sidekiq::Worker }
|
2017-11-28 16:08:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|