Class: AsyncExperiments::ExperimentResult

Inherits:
Object
  • Object
show all
Defined in:
lib/async_experiments/experiment_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, id, type, redis, statsd, run_output = nil, duration = nil) ⇒ ExperimentResult

Returns a new instance of ExperimentResult.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/async_experiments/experiment_result.rb', line 8

def initialize(name, id, type, redis, statsd, run_output = nil, duration = nil)
  @name = name
  @key = "#{name}:#{id}"
  @redis = redis
  @statsd = statsd
  @type = type
  @run_output = run_output
  @duration = duration

  if Util.blank?(duration)
    redis_data = data_from_redis

    if redis_data
      @run_output ||= redis_data.fetch(:run_output)
      @duration ||= redis_data.fetch(:duration)
    end
  end
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



27
28
29
# File 'lib/async_experiments/experiment_result.rb', line 27

def duration
  @duration
end

#keyObject (readonly)

Returns the value of attribute key.



27
28
29
# File 'lib/async_experiments/experiment_result.rb', line 27

def key
  @key
end

#run_outputObject (readonly)

Returns the value of attribute run_output.



27
28
29
# File 'lib/async_experiments/experiment_result.rb', line 27

def run_output
  @run_output
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/async_experiments/experiment_result.rb', line 44

def available?
  Util.present?(duration)
end

#process_run_output(candidate, expiry) ⇒ Object



38
39
40
41
42
# File 'lib/async_experiments/experiment_result.rb', line 38

def process_run_output(candidate, expiry)
  variation = HashDiff.diff(sort(self.run_output), sort(candidate.run_output))
  report_data(variation, candidate, expiry)
  redis.del("experiments:#{key}:candidate")
end

#store_run_output(expiry) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/async_experiments/experiment_result.rb', line 29

def store_run_output(expiry)
  redis_key = "experiments:#{key}:#{type}"
  redis.set(redis_key, {
    run_output: run_output,
    duration: duration,
  }.to_json)
  redis.expire(redis_key, expiry)
end