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 +4 -4
- data/lib/upfluence/thread.rb +46 -0
- data/lib/upfluence/utils/version.rb +1 -1
- data/lib/upfluence/utils.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 422d6056047e387e14e46823773b9ba7f1d3463657b1ac5797a4c492ee772db8
|
4
|
+
data.tar.gz: 113685a071e08a026bc2518567b9539698b4f9be99a1b24b344e41b73c81b346
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/upfluence/utils.rb
CHANGED
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.
|
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-
|
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
|