Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for wildcard keys. #99

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/resque/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a little cleaner..

{}.tap do |hash|
  wildcard_keys.each do |wildcard_key|
    hash[wildcard_key] = 1
  end
end


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