upfluence-utils 0.12.10 → 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: 12233490ac89cab19faeb8f472bc5ab0c3ab044b532ec70f6935e5b12b7c0204
4
- data.tar.gz: 31f174d80c1972eb64526ed4bd61de626ce4223c9b7842139a8920d344b043a0
3
+ metadata.gz: 422d6056047e387e14e46823773b9ba7f1d3463657b1ac5797a4c492ee772db8
4
+ data.tar.gz: 113685a071e08a026bc2518567b9539698b4f9be99a1b24b344e41b73c81b346
5
5
  SHA512:
6
- metadata.gz: 7f6bc65b8e596e2c8b77f5f8902b9a3643470608fbf10962e1c5bd027c3b24c72f7ebe8b67e763d97939c7bc8460c4eac5a55cb09dcd7dbd6f5726696bde1244
7
- data.tar.gz: a72ff7ef5ca46b2e66724316da642a8276d1e844f1d314c1e3dffe615d35f6c2b05a6a23a515f56f746d12eb054961b495975eaaf744a49e561fdf08c50f248b
6
+ metadata.gz: 0e243d46b108b49effee29ebc105ffeb498d69554158267308d9665d6f4be6c7d0dd6e581e1479186fdb0f9e87857aafeb8fbf4cad29d3a1a2d2c1daed54ed8a
7
+ data.tar.gz: 68d33676ad949085e6ee8a8f456fb9d792b94f8438bd16b93f41e679a82bfe70b1291bdedf677e35f1ed1f727a57fc4ab84a9e77de1f83cd241acee66bbf5e10
@@ -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.10'.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.10
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: 2025-01-30 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