test_track_rails_client 4.0.2 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 854dd7b85c56a6b115c1c36ae4139fcc066290c78611260efe7e1a5cba5873db
4
- data.tar.gz: 31ebfcbc833a484c4406faadbbe4c6dafb02e3e1ff1451a190628a964455a635
3
+ metadata.gz: '0667053993d876c5694d5211c1204251ec5cf56436d037e83e9baa32896753d1'
4
+ data.tar.gz: 1fac803ce98a9182211fb91e19c8ab6ec08d7c151ff7937427daf24e6239fac2
5
5
  SHA512:
6
- metadata.gz: a979df0d5cb9f1439c22a099f717709993d1eb78648fe88e1251faa2f9d5d15645a748dd6cb9c981c521a0af34affdea1be700cb831c6a258bb148fbab5912c8
7
- data.tar.gz: af422d4454c05b9a548aafcb5953f2ec4db0853a2f31d44f5afb14deea418974ae7bfc2232ce94afa89ed8068f989f8ef752426de64e5fff3ad7e236efe3e633
6
+ metadata.gz: 57f91d6a7003b43b3cac7adfee73ad7fb904730a220af65f552e5875331fc7622d2cc68ba9d654d0843e511aa74741d5ceec5d93823f45378c058e26558087f6
7
+ data.tar.gz: c23ebed46c96893e5f487b409d9550587c4355c3536d5cc9cc51d2ea229c08fa1dbf1d7b35e9979e2728e214367682367c73700ecef38cebf912cff5e3f0e434
@@ -0,0 +1,4 @@
1
+ module TestTrack
2
+ class ApplicationJob < TestTrack.job_base_class_name.constantize
3
+ end
4
+ end
@@ -0,0 +1,71 @@
1
+ module TestTrack
2
+ class AssignmentEventJob < ApplicationJob
3
+ attr_reader :visitor_id, :assignment
4
+
5
+ def perform(visitor_id:, split_name:, variant:, context:)
6
+ raise "visitor_id must be present" if visitor_id.blank?
7
+ raise "split_name must be present" if visitor_id.blank?
8
+
9
+ @visitor_id = visitor_id
10
+ @assignment = build_assignment(visitor_id, split_name, variant, context)
11
+
12
+ create_assignment_event!
13
+ end
14
+
15
+ private
16
+
17
+ def build_assignment(visitor_id, split_name, variant, context)
18
+ assignment = Assignment.new(
19
+ visitor: Visitor.new(id: visitor_id),
20
+ split_name: split_name
21
+ )
22
+ assignment.variant = variant
23
+ assignment.context = context
24
+ assignment
25
+ end
26
+
27
+ def create_assignment_event!
28
+ tracking_result = maybe_track
29
+ unless assignment.feature_gate?
30
+ Remote::AssignmentEvent.create!(
31
+ visitor_id: visitor_id,
32
+ split_name: assignment.split_name,
33
+ context: assignment.context,
34
+ mixpanel_result: tracking_result
35
+ )
36
+ end
37
+ end
38
+
39
+ def maybe_track
40
+ return "failure" unless TestTrack.enabled?
41
+ return "success" if skip_analytics_event?
42
+
43
+ result = TestTrack.analytics.track(AnalyticsEvent.new(visitor_id, assignment))
44
+ result ? "success" : "failure"
45
+ end
46
+
47
+ def skip_analytics_event?
48
+ assignment.feature_gate? && skip_experience_event?
49
+ end
50
+
51
+ def skip_experience_event?
52
+ skip_all_experience_events? || !sample_event?
53
+ end
54
+
55
+ def skip_all_experience_events?
56
+ experience_sampling_weight.zero?
57
+ end
58
+
59
+ def sample_event?
60
+ Kernel.rand(experience_sampling_weight).zero?
61
+ end
62
+
63
+ def experience_sampling_weight
64
+ @experience_sampling_weight ||= split_registry.experience_sampling_weight
65
+ end
66
+
67
+ def split_registry
68
+ @split_registry ||= SplitRegistry.from_remote
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,11 @@
1
+ module TestTrack
2
+ class IdentifierCreationJob < ApplicationJob
3
+ def perform(identifier_type:, visitor_id:, value:)
4
+ Remote::Identifier.create!(
5
+ identifier_type: identifier_type,
6
+ visitor_id: visitor_id,
7
+ value: value
8
+ )
9
+ end
10
+ end
11
+ end
@@ -13,21 +13,21 @@ class TestTrack::UnsyncedAssignmentsNotifier
13
13
 
14
14
  def notify
15
15
  assignments.each do |assignment|
16
- build_notify_assignment_job(assignment).tap do |job|
17
- job.perform
18
- rescue *TestTrack::SERVER_ERRORS => e
19
- Rails.logger.error "TestTrack failed to notify unsynced assignments, retrying. #{e}"
20
- Delayed::Job.enqueue(build_notify_assignment_job(assignment))
21
- end
16
+ TestTrack::AssignmentEventJob.perform_now assignment_job_args(assignment)
17
+ rescue *TestTrack::SERVER_ERRORS => e
18
+ Rails.logger.error "TestTrack failed to notify unsynced assignments, retrying. #{e}"
19
+ TestTrack::AssignmentEventJob.perform_later assignment_job_args(assignment)
22
20
  end
23
21
  end
24
22
 
25
23
  private
26
24
 
27
- def build_notify_assignment_job(assignment)
28
- TestTrack::NotifyAssignmentJob.new(
25
+ def assignment_job_args(assignment)
26
+ {
29
27
  visitor_id: visitor_id,
30
- assignment: assignment
31
- )
28
+ context: assignment.context,
29
+ split_name: assignment.split_name,
30
+ variant: assignment.variant
31
+ }
32
32
  end
33
33
  end
@@ -78,7 +78,7 @@ class TestTrack::Visitor
78
78
 
79
79
  # If at first you don't succeed, async it - we may not display 100% consistent UX this time,
80
80
  # but subsequent requests will be better off
81
- TestTrack::Remote::Identifier.delay.create!(opts)
81
+ TestTrack::IdentifierCreationJob.perform_later(opts)
82
82
  end
83
83
  end
84
84
 
data/lib/test_track.rb CHANGED
@@ -20,6 +20,7 @@ module TestTrack
20
20
  BUILD_TIMESTAMP_REGEX = /\A\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(.\d+)?([+-][0-2]\d:[0-5]\d|Z)\z/.freeze
21
21
 
22
22
  mattr_accessor :enabled_override, :app_name
23
+ mattr_accessor(:job_base_class_name) { 'ActiveJob::Base' }
23
24
 
24
25
  class << self
25
26
  def analytics
@@ -1,19 +1,5 @@
1
- require 'delayed_job'
2
-
3
- begin
4
- require 'airbrake'
5
- rescue LoadError
6
- # no-op
7
- end
8
-
9
- unless defined?(Delayed::Plugins::Airbrake) && Delayed::Worker.plugins.include?(Delayed::Plugins::Airbrake)
10
- begin
11
- require 'delayed-plugins-airbrake'
12
- rescue LoadError
13
- # no-op
14
- end
15
- end
16
-
1
+ require 'active_job'
2
+ require 'active_model'
17
3
  require 'test_track'
18
4
 
19
5
  module TestTrackRailsClient
@@ -1,3 +1,3 @@
1
1
  module TestTrackRailsClient
2
- VERSION = "4.0.2" # rubocop:disable Style/MutableConstant
2
+ VERSION = "5.0.0" # rubocop:disable Style/MutableConstant
3
3
  end
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.require_paths = ["lib"]
16
16
 
17
17
  spec.add_dependency 'her'
18
- spec.add_dependency 'rails', '>= 4.1', '< 5.2'
18
+ spec.add_dependency 'activesupport'
19
19
 
20
20
  spec.add_development_dependency 'appraisal', '~> 2.2.0'
21
21
  end
@@ -1,6 +1,6 @@
1
1
  require 'her'
2
2
  require 'active_support/concern'
3
- require 'rails'
3
+ require 'active_support/callbacks'
4
4
 
5
5
  module FakeableHer
6
6
  module Model
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_track_rails_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.2
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan O'Neill
@@ -10,39 +10,39 @@ authors:
10
10
  - John Mileham
11
11
  - Alan Norton
12
12
  - Sam Moore
13
- autorequire:
13
+ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2021-03-24 00:00:00.000000000 Z
16
+ date: 2021-05-18 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
- name: delayed_job
19
+ name: activejob
20
20
  requirement: !ruby/object:Gem::Requirement
21
21
  requirements:
22
- - - "~>"
22
+ - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: '4.0'
24
+ version: '5.1'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
- - - "~>"
29
+ - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: '4.0'
31
+ version: '5.1'
32
32
  - !ruby/object:Gem::Dependency
33
- name: delayed_job_active_record
33
+ name: activemodel
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
36
  - - ">="
37
37
  - !ruby/object:Gem::Version
38
- version: '0'
38
+ version: '5.1'
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: '5.1'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: faraday
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -120,25 +120,19 @@ dependencies:
120
120
  - !ruby/object:Gem::Version
121
121
  version: 3.0.0
122
122
  - !ruby/object:Gem::Dependency
123
- name: rails
123
+ name: railties
124
124
  requirement: !ruby/object:Gem::Requirement
125
125
  requirements:
126
126
  - - ">="
127
127
  - !ruby/object:Gem::Version
128
- version: '4.1'
129
- - - "<"
130
- - !ruby/object:Gem::Version
131
- version: '7.0'
128
+ version: '5.1'
132
129
  type: :runtime
133
130
  prerelease: false
134
131
  version_requirements: !ruby/object:Gem::Requirement
135
132
  requirements:
136
133
  - - ">="
137
134
  - !ruby/object:Gem::Version
138
- version: '4.1'
139
- - - "<"
140
- - !ruby/object:Gem::Version
141
- version: '7.0'
135
+ version: '5.1'
142
136
  - !ruby/object:Gem::Dependency
143
137
  name: request_store
144
138
  requirement: !ruby/object:Gem::Requirement
@@ -153,6 +147,20 @@ dependencies:
153
147
  - - "~>"
154
148
  - !ruby/object:Gem::Version
155
149
  version: '1.3'
150
+ - !ruby/object:Gem::Dependency
151
+ name: sprockets-rails
152
+ requirement: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ type: :runtime
158
+ prerelease: false
159
+ version_requirements: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
156
164
  - !ruby/object:Gem::Dependency
157
165
  name: appraisal
158
166
  requirement: !ruby/object:Gem::Requirement
@@ -279,20 +287,6 @@ dependencies:
279
287
  - - ">="
280
288
  - !ruby/object:Gem::Version
281
289
  version: '0'
282
- - !ruby/object:Gem::Dependency
283
- name: sqlite3
284
- requirement: !ruby/object:Gem::Requirement
285
- requirements:
286
- - - ">="
287
- - !ruby/object:Gem::Version
288
- version: '0'
289
- type: :development
290
- prerelease: false
291
- version_requirements: !ruby/object:Gem::Requirement
292
- requirements:
293
- - - ">="
294
- - !ruby/object:Gem::Version
295
- version: '0'
296
290
  - !ruby/object:Gem::Dependency
297
291
  name: timecop
298
292
  requirement: !ruby/object:Gem::Requirement
@@ -344,6 +338,9 @@ files:
344
338
  - app/controllers/tt/api/v1/visitor_details_controller.rb
345
339
  - app/controllers/tt/api/v1/visitors_controller.rb
346
340
  - app/helpers/test_track/application_helper.rb
341
+ - app/jobs/test_track/application_job.rb
342
+ - app/jobs/test_track/assignment_event_job.rb
343
+ - app/jobs/test_track/identifier_creation_job.rb
347
344
  - app/models/concerns/test_track/identity.rb
348
345
  - app/models/concerns/test_track/remote_model.rb
349
346
  - app/models/concerns/test_track/required_options.rb
@@ -448,7 +445,7 @@ homepage: https://github.com/Betterment
448
445
  licenses:
449
446
  - MIT
450
447
  metadata: {}
451
- post_install_message:
448
+ post_install_message:
452
449
  rdoc_options: []
453
450
  require_paths:
454
451
  - lib
@@ -463,8 +460,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
463
460
  - !ruby/object:Gem::Version
464
461
  version: '0'
465
462
  requirements: []
466
- rubygems_version: 3.1.4
467
- signing_key:
463
+ rubygems_version: 3.2.17
464
+ signing_key:
468
465
  specification_version: 4
469
466
  summary: Rails client for TestTrack
470
467
  test_files: []