diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-29 12:08:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-29 12:08:46 +0300 |
commit | f931527bc5120097db15737f8594a431bcad9116 (patch) | |
tree | 9f222683bb0ee7b88e3f7c0e02362a530e3c98a6 /app/experiments | |
parent | fd3d0d4c2c5ecac651fdeff92a1f2e4c927e05e0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/experiments')
-rw-r--r-- | app/experiments/members/invite_email_experiment.rb | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/app/experiments/members/invite_email_experiment.rb b/app/experiments/members/invite_email_experiment.rb deleted file mode 100644 index 893061e34f3..00000000000 --- a/app/experiments/members/invite_email_experiment.rb +++ /dev/null @@ -1,93 +0,0 @@ -# frozen_string_literal: true - -module Members - class InviteEmailExperiment < ApplicationExperiment - exclude { context.actor.created_by.blank? } - exclude { context.actor.created_by.avatar_url.nil? } - - INVITE_TYPE = 'initial_email' - - def self.initial_invite_email?(invite_type) - invite_type == INVITE_TYPE - end - - def resolve_variant_name - RoundRobin.new(feature_flag_name, %i[activity control]).execute - end - end - - class RoundRobin - CacheError = Class.new(StandardError) - - COUNTER_EXPIRE_TIME = 86400 # one day - - def initialize(key, variants) - @key = key - @variants = variants - end - - def execute - increment_counter - resolve_variant_name - end - - # When the counter would expire - # - # @api private Used internally by SRE and debugging purpose - # @return [Integer] Number in seconds until expiration or false if never - def counter_expires_in - Gitlab::Redis::SharedState.with do |redis| - redis.ttl(key) - end - end - - # Return the actual counter value - # - # @return [Integer] value - def counter_value - Gitlab::Redis::SharedState.with do |redis| - (redis.get(key) || 0).to_i - end - end - - # Reset the counter - # - # @private Used internally by SRE and debugging purpose - # @return [Boolean] whether reset was a success - def reset! - redis_cmd do |redis| - redis.del(key) - end - end - - private - - attr_reader :key, :variants - - # Increase the counter - # - # @return [Boolean] whether operation was a success - def increment_counter - redis_cmd do |redis| - redis.incr(key) - redis.expire(key, COUNTER_EXPIRE_TIME) - end - end - - def resolve_variant_name - remainder = counter_value % variants.size - - variants[remainder] - end - - def redis_cmd - Gitlab::Redis::SharedState.with { |redis| yield(redis) } - - true - rescue CacheError => e - Gitlab::AppLogger.warn("GitLab: An unexpected error occurred in writing to Redis: #{e}") - - false - end - end -end |