posthog-ruby 1.2.4 → 1.3.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: 48c747d4d40d5c783c8f53c03fbc7324c5de7d41521293c8aef8d1d76a7b19dd
4
- data.tar.gz: 03f2cf98045fa5bd21cac93fd0858453c5087950cd764d6144c8f98690deae65
3
+ metadata.gz: 4cc2c1e12c53fc80013ff8d49d082d1d35ad625fa0db972e53afbc205f595664
4
+ data.tar.gz: f95c1cb5502e0ae2d58e10b0575065fb797bbccd73d96098249a50ab6f60ee0a
5
5
  SHA512:
6
- metadata.gz: 68b3a6223048f1e4a36f6ef7546d5f69651c12ce55e53e4cf9ae0518ac16fe08695071a1439feeb98ed0a0e656fdae34aa0a40f985c4d4e9e0b0876262dfb028
7
- data.tar.gz: 0b5a18f99c9d208f8803c1f6d4e30db96efceec768b0a25b7de794de436da1ab323d176b90d854a4392e5931418a661ab9812771da75d4c6584a5be4bc5ea427
6
+ metadata.gz: 8947ba953b888db638dff4ee913fa697eb80d0ac4e8796a705143278bae9aef67d7d966cdb6112309e2a51b5432fe340676036f2756bcbef885f801c929de13d
7
+ data.tar.gz: c95c85e49f02acd99043120ccc6b7889b30553da9d968cdc08f7bfe13e130bd5f42380a68714c712f0444777a24bfcb29e252a28ce319f01242a362c9ca2e4e0
@@ -4,7 +4,8 @@ require 'time'
4
4
  require 'posthog/defaults'
5
5
  require 'posthog/logging'
6
6
  require 'posthog/utils'
7
- require 'posthog/worker'
7
+ require 'posthog/send_worker'
8
+ require 'posthog/noop_worker'
8
9
  require 'posthog/feature_flags'
9
10
 
10
11
  class PostHog
@@ -15,7 +16,9 @@ class PostHog
15
16
  # @param [Hash] opts
16
17
  # @option opts [String] :api_key Your project's api_key
17
18
  # @option opts [FixNum] :max_queue_size Maximum number of calls to be
18
- # remain queued.
19
+ # remain queued. Defaults to 10_000.
20
+ # @option opts [Bool] :test_mode +true+ if messages should remain
21
+ # queued for testing. Defaults to +false+.
19
22
  # @option opts [Proc] :on_error Handles error calls from the API.
20
23
  def initialize(opts = {})
21
24
  symbolize_keys!(opts)
@@ -24,7 +27,11 @@ class PostHog
24
27
  @api_key = opts[:api_key]
25
28
  @max_queue_size = opts[:max_queue_size] || Defaults::Queue::MAX_SIZE
26
29
  @worker_mutex = Mutex.new
27
- @worker = Worker.new(@queue, @api_key, opts)
30
+ @worker = if opts[:test_mode]
31
+ NoopWorker.new(@queue)
32
+ else
33
+ SendWorker.new(@queue, @api_key, opts)
34
+ end
28
35
  @worker_thread = nil
29
36
  @feature_flags_poller = nil
30
37
  @personal_api_key = nil
@@ -45,7 +52,7 @@ class PostHog
45
52
  at_exit { @worker_thread && @worker_thread[:should_exit] = true }
46
53
  end
47
54
 
48
- # Synchronously waits until the worker has flushed the queue.
55
+ # Synchronously waits until the worker has cleared the queue.
49
56
  #
50
57
  # Use only for scripts which are not long-running, and will specifically
51
58
  # exit
@@ -56,6 +63,13 @@ class PostHog
56
63
  end
57
64
  end
58
65
 
66
+ # Clears the queue without waiting.
67
+ #
68
+ # Use only in test mode
69
+ def clear
70
+ @queue.clear
71
+ end
72
+
59
73
  # @!macro common_attrs
60
74
  # @option attrs [String] :message_id ID that uniquely
61
75
  # identifies a message across the API. (optional)
@@ -96,6 +110,11 @@ class PostHog
96
110
  enqueue(FieldParser.parse_for_alias(attrs))
97
111
  end
98
112
 
113
+ # @return [Hash] pops the last message from the queue
114
+ def dequeue_last_message
115
+ @queue.pop
116
+ end
117
+
99
118
  # @return [Fixnum] number of messages in the queue
100
119
  def queued_messages
101
120
  @queue.length
@@ -0,0 +1,16 @@
1
+ # A worker that doesn't consume jobs
2
+ class PostHog
3
+ class NoopWorker
4
+ def initialize(queue)
5
+ @queue = queue
6
+ end
7
+
8
+ def run
9
+ # Does nothing
10
+ end
11
+
12
+ def is_requesting?
13
+ false
14
+ end
15
+ end
16
+ end
@@ -4,7 +4,7 @@ require 'posthog/transport'
4
4
  require 'posthog/utils'
5
5
 
6
6
  class PostHog
7
- class Worker
7
+ class SendWorker
8
8
  include PostHog::Utils
9
9
  include PostHog::Defaults
10
10
  include PostHog::Logging
@@ -1,3 +1,3 @@
1
1
  class PostHog
2
- VERSION = '1.2.4'
2
+ VERSION = '1.3.0'
3
3
  end
data/lib/posthog.rb CHANGED
@@ -3,7 +3,7 @@ require 'posthog/defaults'
3
3
  require 'posthog/utils'
4
4
  require 'posthog/field_parser'
5
5
  require 'posthog/client'
6
- require 'posthog/worker'
6
+ require 'posthog/send_worker'
7
7
  require 'posthog/transport'
8
8
  require 'posthog/response'
9
9
  require 'posthog/logging'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posthog-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-30 00:00:00.000000000 Z
11
+ date: 2022-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -153,16 +153,17 @@ files:
153
153
  - lib/posthog/field_parser.rb
154
154
  - lib/posthog/logging.rb
155
155
  - lib/posthog/message_batch.rb
156
+ - lib/posthog/noop_worker.rb
156
157
  - lib/posthog/response.rb
158
+ - lib/posthog/send_worker.rb
157
159
  - lib/posthog/transport.rb
158
160
  - lib/posthog/utils.rb
159
161
  - lib/posthog/version.rb
160
- - lib/posthog/worker.rb
161
162
  homepage: https://github.com/PostHog/posthog-ruby
162
163
  licenses:
163
164
  - MIT
164
165
  metadata: {}
165
- post_install_message:
166
+ post_install_message:
166
167
  rdoc_options: []
167
168
  require_paths:
168
169
  - lib
@@ -177,8 +178,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
178
  - !ruby/object:Gem::Version
178
179
  version: '0'
179
180
  requirements: []
180
- rubygems_version: 3.0.3
181
- signing_key:
181
+ rubygems_version: 3.1.6
182
+ signing_key:
182
183
  specification_version: 4
183
184
  summary: PostHog library
184
185
  test_files: []