app_profiler 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94eb2e555af032b1b54f392d98d3fa5f6b6fa1cff7aa76fc2092f24b00cdfe9f
4
- data.tar.gz: 94e0901199de37232236a09ce66b6adaf61e2a23374c2eed736f603a004e8990
3
+ metadata.gz: 5a4f543410317515564af0f46a5f437e33af8a7c66334e6cfd42830e37dfb89c
4
+ data.tar.gz: bb37127c11ae94eade6d736d14d3609e7e99854709659dd9b7bb081e8cbb86b3
5
5
  SHA512:
6
- metadata.gz: ec60f80896dff0a664faa2d807c09afd154494325a68c6e418e4f9b48765f42b8452f5f6a44253e46e9747513fd80b3835a762fb6a3fdf8cac0ac8086ec3099c
7
- data.tar.gz: 4b88a7df76dfaac8d918674675c5dc7a5acae867e7bc4e62ba496aa13952bf02d450a26e1942e394914b98483ff4ebe4afebc7903b04cd669e9485aaac33382c
6
+ metadata.gz: 5a6da942b841feddb9b78d8a212b4c546b89e4966130419c87ad167f5c698301753fa4c14c4a6548338b341b217fed8418a71e9ceb2dc3a9289211436c036bd8
7
+ data.tar.gz: bdb22060ba83526a177c34302e731960d4eff6c563efe313f19e8282535632fa61c71ba269ce90700066166b6102244b1b1cdf6463b97d877fc45deb27828127
@@ -37,6 +37,9 @@ module AppProfiler
37
37
  AppProfiler.upload_queue_max_length = app.config.app_profiler.upload_queue_max_length || 10
38
38
  AppProfiler.upload_queue_interval_secs = app.config.app_profiler.upload_queue_interval_secs || 5
39
39
  AppProfiler.profile_file_prefix = app.config.app_profiler.profile_file_prefix || DefaultProfilePrefix
40
+ AppProfiler.profile_enqueue_success = app.config.app_profiler.profile_enqueue_success
41
+ AppProfiler.profile_enqueue_failure = app.config.app_profiler.profile_enqueue_failure
42
+ AppProfiler.after_process_queue = app.config.app_profiler.after_process_queue
40
43
  end
41
44
 
42
45
  initializer "app_profiler.add_middleware" do |app|
@@ -37,8 +37,10 @@ module AppProfiler
37
37
  @queue ||= init_queue
38
38
  begin
39
39
  @queue.push(profile, true) # non-blocking push, raises ThreadError if queue is full
40
+ AppProfiler.profile_enqueue_success&.call
40
41
  rescue ThreadError
41
42
  AppProfiler.logger.info("[AppProfiler] upload queue is full, profile discarded")
43
+ AppProfiler.profile_enqueue_failure&.call(profile)
42
44
  end
43
45
  end
44
46
  end
@@ -80,7 +82,12 @@ module AppProfiler
80
82
 
81
83
  return unless queue
82
84
 
83
- queue.size.times { queue.pop(false).upload }
85
+ num_success = 0
86
+ num_failures = 0
87
+ queue.size.times do
88
+ queue.pop(false).upload ? num_success += 1 : num_failures += 1
89
+ end
90
+ AppProfiler.after_process_queue&.call(num_success, num_failures)
84
91
  end
85
92
 
86
93
  def gcs_filename(profile)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppProfiler
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.8"
5
5
  end
data/lib/app_profiler.rb CHANGED
@@ -55,6 +55,9 @@ module AppProfiler
55
55
  mattr_accessor :upload_queue_max_length, default: 10
56
56
  mattr_accessor :upload_queue_interval_secs, default: 5
57
57
  mattr_accessor :profile_file_prefix, default: DefaultProfilePrefix
58
+ mattr_reader :profile_enqueue_success, default: nil
59
+ mattr_reader :profile_enqueue_failure, default: nil
60
+ mattr_reader :after_process_queue, default: nil
58
61
 
59
62
  class << self
60
63
  def run(*args, &block)
@@ -88,6 +91,30 @@ module AppProfiler
88
91
  @@profile_url_formatter = block # rubocop:disable Style/ClassVars
89
92
  end
90
93
 
94
+ def profile_enqueue_success=(handler)
95
+ if handler && (!handler.is_a?(Proc) || (handler.lambda? && handler.arity != 0))
96
+ raise ArgumentError, "profile_enqueue_success must be proc or a lambda that accepts no argument"
97
+ end
98
+
99
+ @@profile_enqueue_success = handler # rubocop:disable Style/ClassVars
100
+ end
101
+
102
+ def profile_enqueue_failure=(handler)
103
+ if handler && (!handler.is_a?(Proc) || (handler.lambda? && handler.arity != 1))
104
+ raise ArgumentError, "profile_enqueue_failure must be a proc or a lambda that accepts one argument"
105
+ end
106
+
107
+ @@profile_enqueue_failure = handler # rubocop:disable Style/ClassVars
108
+ end
109
+
110
+ def after_process_queue=(handler)
111
+ if handler && (!handler.is_a?(Proc) || (handler.lambda? && handler.arity != 2))
112
+ raise ArgumentError, "after_process_queue must be a proc or a lambda that accepts two arguments"
113
+ end
114
+
115
+ @@after_process_queue = handler # rubocop:disable Style/ClassVars
116
+ end
117
+
91
118
  def profile_url(upload)
92
119
  return unless AppProfiler.profile_url_formatter
93
120
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gannon McGibbon
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2023-10-20 00:00:00.000000000 Z
16
+ date: 2023-11-06 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activesupport