Sha256: db0584a4548feab65e328d01f4ddf967d4b1ef712138311023f90cdc3e8ce119

Contents?: true

Size: 893 Bytes

Versions: 3

Compression:

Stored size: 893 Bytes

Contents

class TestTrack::NotifyAssignmentJob
  attr_reader :visitor_id, :assignment

  def initialize(opts)
    @visitor_id = opts.delete(:visitor_id)
    @assignment = opts.delete(:assignment)

    %w(visitor_id assignment).each do |param_name|
      raise "#{param_name} must be present" if send(param_name).blank?
    end
    raise "unknown opts: #{opts.keys.to_sentence}" if opts.present?
  end

  def perform
    tracking_result = track
    unless assignment.feature_gate?
      TestTrack::Remote::AssignmentEvent.create!(
        visitor_id: visitor_id,
        split_name: assignment.split_name,
        context: assignment.context,
        mixpanel_result: tracking_result
      )
    end
  end

  private

  def track
    return "failure" unless TestTrack.enabled?
    result = TestTrack.analytics.track(TestTrack::AnalyticsEvent.new(assignment))
    result ? "success" : "failure"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
test_track_rails_client-4.0.0.alpha8 app/models/test_track/notify_assignment_job.rb
test_track_rails_client-4.0.0.alpha7 app/models/test_track/notify_assignment_job.rb
test_track_rails_client-4.0.0.alpha6 app/models/test_track/notify_assignment_job.rb