Module: AsyncExperiments::ExperimentControl

Defined in:
lib/async_experiments/experiment_control.rb

Instance Method Summary collapse

Instance Method Details

#experiment_control(name, candidate:) ⇒ Object



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

def experiment_control(name, candidate:)
  start_time = Time.now
  run_output = yield
  duration = (Time.now - start_time).to_f

  id = SecureRandom.uuid

  if run_output.class == Enumerator
    run_output = run_output.to_a
  end

  ExperimentResultWorker.perform_async(name, id, run_output, duration, :control)

  candidate_worker = candidate.fetch(:worker)
  candidate_worker.perform_async(*candidate.fetch(:args),
    name: name,
    id: id,
  )

  run_output
end