Skip to content

Instantly share code, notes, and snippets.

@yosemsweet
Created January 2, 2015 01:08
Show Gist options
  • Save yosemsweet/1e22c770c09d8196a2a2 to your computer and use it in GitHub Desktop.
Save yosemsweet/1e22c770c09d8196a2a2 to your computer and use it in GitHub Desktop.
config/bandit.rb
# Use this setup block to configure all options for Bandit.
Bandit.setup do |config|
bandit_store = ENV['BANDIT_STORE'] || 'redis'
bandit_store_config = { }
case bandit_store
when 'redis'
bandit_store_config['url'] = ENV['REDIS_URL']
when 'dalli'
bandit_store_config['host'] = ENV['MEMCACHE_SERVERS'] || '127.0.0.1'
bandit_store_config['namespace'] = ENV['BANDIT_NAMESPACE'] || 'bandit'
bandit_store_config['port'] = ENV['MEMCACHE_PORT'] || 11211
when 'memcache'
bandit_store_config['host'] = ENV['MEMCACHE_URL'] || '127.0.0.1:1121'
when 'pstore'
file_path = ENV['BANDIT_STORE_PATH'] || 'bandit_store'
if !!ENV['BANDIT_USE_YAML_STORE']
bandit_store_config['use_yaml_store'] = true
file_path << '.yamlstore'
else
file_path << '.pstore'
end
bandit_store_config['file'] = file_path
else
raise RuntimeException('Bandit - No storage strategy found.')
end
bandit_player = ENV['BANDIT_PLAYER'] || 'round_robin'
bandit_player_config = {}
case bandit_player
when 'epsilon_greedy'
bandit_storage_config['epsilon'] = ENV['BANDIT_EPSILON'] || 0.1
end
config.player = bandit_player
config.player_config = bandit_player_config
config.storage = bandit_store
config.storage_config = bandit_store_config
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment