lib/verdict/experiment.rb in verdict-0.13.0 vs lib/verdict/experiment.rb in verdict-0.14.0
- old
+ new
@@ -50,21 +50,33 @@
@segmenter.instance_eval(&block)
@segmenter.verify!
return self
end
- # Optional: Together with the "end timestamp", limits the experiment run timeline within
- # the given time interval. When experiment is not scheduled, subject switch returns nil.
- # This is useful when the experimenter requires the experiment to run in a strict timeline.
+ # Optional: Together with the "end_timestamp" and "stop_new_assignment_timestamp", limits the experiment run timeline within
+ # the given time interval.
+ #
+ # Timestamps definitions:
+ # start_timestamp: Experiment's start time. No assignments are made i.e. switch will return nil before this timestamp.
+ # stop_new_assignment_timestamp: Experiment's new assignment stop time. No new assignments are made
+ # i.e. switch returns nil for new assignments but the existing assignments are preserved.
+ # end_timestamp: Experiment's end time. No assignments are made i.e. switch returns nil after this timestamp.
+ #
+ # Experiment run timeline:
+ # start_timestamp -> (new assignments occur) -> stop_new_assignment_timestamp -> (no new assignments occur) -> end_timestamp
def schedule_start_timestamp(timestamp)
@schedule_start_timestamp = timestamp
end
def schedule_end_timestamp(timestamp)
@schedule_end_timestamp = timestamp
end
+ def schedule_stop_new_assignment_timestamp(timestamp)
+ @schedule_stop_new_assignment_timestamp = timestamp
+ end
+
def rollout_percentage(percentage, rollout_group_name = :enabled)
groups(Verdict::Segmenters::RolloutSegmenter) do
group rollout_group_name, percentage
end
end
@@ -134,11 +146,11 @@
previous_assignment = lookup(subject)
subject_identifier = retrieve_subject_identifier(subject)
assignment = if previous_assignment
previous_assignment
- elsif subject_qualifies?(subject, context)
+ elsif subject_qualifies?(subject, context) && is_make_new_assignments?
group = segmenter.assign(subject_identifier, subject, context)
subject_assignment(subject, group, nil, group.nil?)
else
nil_assignment(subject)
end
@@ -266,14 +278,18 @@
end
private
def is_scheduled?
- if @schedule_start_timestamp and @schedule_start_timestamp > Time.now
+ if @schedule_start_timestamp && @schedule_start_timestamp > Time.now
return false
end
- if @schedule_end_timestamp and @schedule_end_timestamp < Time.now
+ if @schedule_end_timestamp && @schedule_end_timestamp <= Time.now
return false
end
return true
+ end
+
+ def is_make_new_assignments?
+ return !(@schedule_stop_new_assignment_timestamp && @schedule_stop_new_assignment_timestamp <= Time.now)
end
end