upfluence-utils 0.12.9 → 0.12.11

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: 0ad61cd35c4b4c028b3c14dabda1472f5a643c85332a3ff1bf70f2b469c19f17
4
- data.tar.gz: f76dc4478c6d50b373c7438dff22b8ed844278de026d058665842bfdf41edfa5
3
+ metadata.gz: 422d6056047e387e14e46823773b9ba7f1d3463657b1ac5797a4c492ee772db8
4
+ data.tar.gz: 113685a071e08a026bc2518567b9539698b4f9be99a1b24b344e41b73c81b346
5
5
  SHA512:
6
- metadata.gz: b95e490013d83ab4ea075fdc3c2b2487b9f936649f2f9b4816e6d9f37e06774fe989f9f6ec117f083795a1730871566463863c0905dc892203d1283fa17c75f6
7
- data.tar.gz: 878a2fe304f2a8176dca49a18f5490a86e21d7ede881e35f044178053f9f1b57147a785e4fda195f36d946782a21801a135bc383f1aecaee9b64544bdd850e00
6
+ metadata.gz: 0e243d46b108b49effee29ebc105ffeb498d69554158267308d9665d6f4be6c7d0dd6e581e1479186fdb0f9e87857aafeb8fbf4cad29d3a1a2d2c1daed54ed8a
7
+ data.tar.gz: 68d33676ad949085e6ee8a8f456fb9d792b94f8438bd16b93f41e679a82bfe70b1291bdedf677e35f1ed1f727a57fc4ab84a9e77de1f83cd241acee66bbf5e10
@@ -4,10 +4,7 @@ module Upfluence
4
4
  module ErrorLogger
5
5
  class Sentry
6
6
  EXCLUDED_ERRORS = (
7
- ::Sentry::Configuration::IGNORE_DEFAULT + [
8
- 'Identity::Thrift::Forbidden',
9
- 'ActiveRecord::RecordNotFound'
10
- ]
7
+ ::Sentry::Configuration::IGNORE_DEFAULT + ['ActiveRecord::RecordNotFound']
11
8
  )
12
9
  MAX_TAG_SIZE = 8 * 1024
13
10
 
@@ -77,7 +74,7 @@ module Upfluence
77
74
  end
78
75
 
79
76
  def middleware
80
- ::Sentry::Rack::CaptureExceptions
77
+ RackMiddleware
81
78
  end
82
79
 
83
80
  def ignore_exception(*klss)
@@ -93,6 +90,16 @@ module Upfluence
93
90
  end
94
91
  end
95
92
 
93
+ class RackMiddleware < ::Sentry::Rack::CaptureExceptions
94
+ def capture_exception(exception, env)
95
+ if env.key? 'sinatra.error'
96
+ return if Sinatra::Base.errors.keys.any? { |klass| exception.is_a?(klass) }
97
+ end
98
+
99
+ super(exception, env)
100
+ end
101
+ end
102
+
96
103
  private
97
104
 
98
105
  def prepare_extra(tags)
@@ -88,6 +88,12 @@ module Upfluence
88
88
  data
89
89
  end
90
90
  end
91
+
92
+ class << self
93
+ def error(*codes, &block)
94
+ Sinatra::Base.error(*codes, &block)
95
+ end
96
+ end
91
97
  end
92
98
 
93
99
  Sinatra::Base.error BadRequest do
@@ -0,0 +1,46 @@
1
+ require 'thread'
2
+
3
+ module Upfluence
4
+ class Thread < ::Thread
5
+ def initialize(**opts, &block)
6
+ thr = self.class.current
7
+ wrappers = self.class.wrappers.reject { |k, _| opts.key?(k) && !opts[k] }.values
8
+
9
+ super do
10
+ wrappers.reduce(block) do |acc, wrapper|
11
+ Proc.new { wrapper.wrap_thread(thr, acc) }
12
+ end.call
13
+ end
14
+ end
15
+
16
+ class << self
17
+ def wrappers
18
+ @wrappers || {}
19
+ end
20
+
21
+ def register_wrapper(name, klass)
22
+ @wrappers ||= {}
23
+ @wrappers[name] = klass
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ begin
30
+ require 'active_record'
31
+
32
+ class ActiveRecordThreadWrapper
33
+ class << self
34
+ def wrap_thread(_thr, block)
35
+ return block.call unless ActiveRecord::Base.connected?
36
+
37
+ ActiveRecord::Base.connection_pool.with_connection do
38
+ block.call
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ Upfluence::Thread.register_wrapper :active_record, ActiveRecordThreadWrapper
45
+ rescue LoadError
46
+ end
@@ -1,5 +1,5 @@
1
1
  module Upfluence
2
2
  module Utils
3
- VERSION = '0.12.9'.freeze
3
+ VERSION = '0.12.11'.freeze
4
4
  end
5
5
  end
@@ -5,3 +5,4 @@ require 'upfluence/utils/semaphore'
5
5
  require 'upfluence/logger'
6
6
  require 'upfluence/error_logger'
7
7
  require 'upfluence/environment'
8
+ require 'upfluence/thread'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upfluence-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.9
4
+ version: 0.12.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Upfluence
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-12 00:00:00.000000000 Z
11
+ date: 2025-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -291,6 +291,7 @@ files:
291
291
  - lib/upfluence/pool.rb
292
292
  - lib/upfluence/resources.rb
293
293
  - lib/upfluence/resources/countries.rb
294
+ - lib/upfluence/thread.rb
294
295
  - lib/upfluence/utils.rb
295
296
  - lib/upfluence/utils/http/middleware/null.rb
296
297
  - lib/upfluence/utils/interval_executor.rb