From bf2fa0d3db240c18ceddfc24f7ebf43f2f3f7ffa Mon Sep 17 00:00:00 2001 From: Umang Chouhan Date: Thu, 9 Jan 2014 14:37:14 +0530 Subject: [PATCH] Adding support for wildcard keys. Excluding key with wildcard. Escaping * for wildcard match. Using #include for wildcard character comparison. Fixing instance variable name. Merging wildcard keys to original configuration. Fixing wildcard key hash. Removing wildcard key after hash is merged. --- lib/resque/pool.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/resque/pool.rb b/lib/resque/pool.rb index 1841c6e..1eb64ce 100644 --- a/lib/resque/pool.rb +++ b/lib/resque/pool.rb @@ -116,6 +116,8 @@ def init_config(config) def load_config if config_file @config = YAML.load(ERB.new(IO.read(config_file)).result) + + add_wildcard_configuration else @config ||= {} end @@ -422,5 +424,33 @@ def create_worker(queues) # }}} + private + def wildcard_keys + config_keys_with_wildcard.collect do |wildcard_key| + wildcard_key_name = wildcard_key.split('*').first + resque_queues_matching_wildcard_key = ::Resque.queues.select { |queue| queue.include?(wildcard_key_name) } + end.flatten + end + + def config_keys_with_wildcard + config.keys.select { |key| key.include?('*') } + end + + def config_hash_for_wildcard_keys + hash = {} + + wildcard_keys.each do |wildcard_key| + hash[wildcard_key] = 1 + end + + hash + end + + def add_wildcard_configuration + unless config_keys_with_wildcard.empty? + config.merge! config_hash_for_wildcard_keys + config_keys_with_wildcard.each { |key| config.except!(key) } + end + end end end