Class: Routemaster::Config

Inherits:
Object
  • Object
show all
Extended by:
Classmethods
Includes:
Singleton
Defined in:
lib/routemaster/config.rb

Defined Under Namespace

Modules: Classmethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Classmethods

method_missing, respond_to?

Instance Attribute Details

#loggerObject



23
24
25
# File 'lib/routemaster/config.rb', line 23

def logger
  @logger ||= NullLogger.new
end

Instance Method Details

#cache_authObject



56
57
58
59
60
61
62
63
# File 'lib/routemaster/config.rb', line 56

def cache_auth
  Hashie::Rash.new.tap do |result|
    ENV.fetch('ROUTEMASTER_CACHE_AUTH', '').split(',').each do |entry|
      host, username, password = entry.split(':')
      result[Regexp.new(host)] = [username, password]
    end
  end
end

#cache_expiryObject



49
50
51
52
53
54
# File 'lib/routemaster/config.rb', line 49

def cache_expiry
  # Do not increase this default value. It's likely that cached data will include PII
  # and 90 days is the maximum permitted retention period at Deliveroo. A higher value
  # means we would need to worry about purging caches at the end of the period.
  Integer(ENV.fetch('ROUTEMASTER_CACHE_EXPIRY', 86_400 * 90))
end

#cache_redisObject



31
32
33
# File 'lib/routemaster/config.rb', line 31

def cache_redis
  RedisBroker.instance.get(:cache_redis, urls: ENV.fetch('ROUTEMASTER_CACHE_REDIS', '').split(','))
end

#drain_redisObject



27
28
29
# File 'lib/routemaster/config.rb', line 27

def drain_redis
  RedisBroker.instance.get(:drain_redis, urls: ENV.fetch('ROUTEMASTER_DRAIN_REDIS', '').split(','))
end

#drain_tokensObject



73
74
75
# File 'lib/routemaster/config.rb', line 73

def drain_tokens
  Set.new(ENV.fetch('ROUTEMASTER_DRAIN_TOKENS').split(','))
end

#hostsObject

Given an ENV format of service:service_root_url,other_service:other_service_root_url Generate a hash of { service => service_root_url, other_service => other_service_root_url }



39
40
41
42
43
44
45
46
47
# File 'lib/routemaster/config.rb', line 39

def hosts
  @hosts ||= begin
               hosts = ENV['ROUTEMASTER_DRAIN_HOSTS'].split(',')
               hosts.inject({}) do |res, host|
                 key, val = host.split(':')
                 res.merge(key => val)
               end
             end
end

#queue_adapterObject



65
66
67
# File 'lib/routemaster/config.rb', line 65

def queue_adapter
  ENV.fetch('ROUTEMASTER_QUEUE_ADAPTER', 'resque').to_sym
end

#queue_nameObject



69
70
71
# File 'lib/routemaster/config.rb', line 69

def queue_name
  ENV.fetch('ROUTEMASTER_QUEUE_NAME', 'routemaster')
end