Skip to content

Instantly share code, notes, and snippets.

@travisliu
Created December 15, 2019 18:55
Show Gist options
  • Save travisliu/e4644ca87a1ebad39b2004d668b16943 to your computer and use it in GitHub Desktop.
Save travisliu/e4644ca87a1ebad39b2004d668b16943 to your computer and use it in GitHub Desktop.
rollout
require 'redis'
require 'rollout'
require 'json'
require 'benchmark'
@redis = Redis.new(host: "redis")
@rollout = Rollout.new(@redis)
users = JSON.parse(File.read("./users.json"))
puts Benchmark.measure {
users.first(1000).each_with_index do |user, index|
puts index if index % 100 == 0
@rollout.active_features(user)
end
}
require 'redis'
require 'rollout'
require 'zlib'
require 'securerandom'
require 'json'
users = []
@redis = Redis.new(host: "redis")
@rollout = Rollout.new(@redis)
8000.times do |index|
users.push("user-" + SecureRandom.uuid)
end
File.open('./users.json', 'w') { |file| file.write(users.to_json) }
groups = []
60.times do |index|
id = "group-" + SecureRandom.uuid
groups.push(id)
@rollout.define_group(id) do |user|
rand = Zlib.crc32(user) % 60
puts "index: #{index}, rand: #{rand}"
rand == index
end
end
File.open('./groups.json', 'w') { |file| file.write(groups.to_json) }
features = []
1000.times do |index|
id = "feature" + SecureRandom.uuid
features.push(id)
groups.sample(6).each do |group|
@rollout.activate_group(id, group)
end
@rollout.activate_users(id, users.sample(1000))
end
File.open('./features.json', 'w') { |file| file.write(features.to_json) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment