Skip to content

Add support for experiment after_run blocks #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2023

Conversation

nickh
Copy link
Member

@nickh nickh commented Mar 18, 2023

This change allows an experiment to run custom behavior based on experiment results, eg

science("my-experiment") do |e|
  e.use { control_method }
  e.try { candidate_method |

  # Slower candidates need further investigation
  e.after_run do |result|
    control_duration = result.control.duration
    candidate_duration = result.candidates.first.duration

    if candidate_duration - control_duration > 15
      Logger.debug("Slow experiment candidate #{context}")
    end
  end
end

To allow an experiment to run custom behavior based on experiment
results, eg:

class MyWidget
  include Scientist

  def users
    science "my-experiment" do |e|
      e.use { control_method }
      e.try { candidate_method }

      # Slower candidates need further investigation
      e.after_run do |result|
        control_duration = result.control.duration
        candidate_duration = result.candidates.first.duration

        if candidate_duration - control_duration > 15
          Logger.debug("Slow experiment candidate #{context}")
        end
      end
    end
  end
end
# Define a block of code to run after an experiment completes, if the experiment
# is enabled.
#
# The block takes no arguments.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block takes the result of the experiment as the argument, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, thanks for catching that! Fixed in 6ea1efc.

@zerowidth zerowidth merged commit 3d05135 into github:main Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants