stack-service-base 0.0.19 → 0.0.21

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: 5dae1479ab73fda6e9e34193fd90cffa89aebaa126633a786e7bd24b335c15cd
4
- data.tar.gz: 815f0c8d16d52c00e434897dbf8155aa7dfc7f7fae47fedaf9dcb53c073acb3a
3
+ metadata.gz: 57b5474b1774d7f28bad212eef759c57005c33c905e7a84cf8ef2ffd703456a5
4
+ data.tar.gz: 2ec3fe1f5b677cc6d5470eb27917a76bd05d0ae77cfa9119de139399e003a4f0
5
5
  SHA512:
6
- metadata.gz: 30b56b345fc51bcac0f26071e7b71dd1b6567f71440a5a5f7b42283dea2c57662a4b691402ea9608b8abd899fdb675a9c118dcda955fa1803caa89b9ddcc94be
7
- data.tar.gz: d602c98f64e443df371bd75a42b460736284ac00b4af0051738f7d0a8df819aed398989590ed2a623420e400a4c0ee112f2d1f644dd6b14208c7d9ddd053a834
6
+ metadata.gz: f65f78c9ddd2261bc215aca0692774b148f968236b9c2cbb767b3b0c43832adc049f96ab9a79d98d6b7c7d1c5ab96ca987398e980daed7646b9f8448cbc8a90a
7
+ data.tar.gz: fa2192cfce9208ac0c72f46c0d75383fdb4f0d73f3cc93d75c24e87ae4398d480857e050502aa9052af8f125092103183b3f90abaf7b1a659dfbf614e0bc61a7
@@ -2,29 +2,31 @@ require 'sequel'
2
2
  require 'async/semaphore'
3
3
  # $stdout.sync = true
4
4
 
5
+ $local_log = -> msg do
6
+ otl_current_span{ |span|
7
+ span.add_event("FiberPool", attributes: {
8
+ F: Fiber.current.__id__, T: Thread.current.__id__, A: self.__id__,
9
+ message: msg
10
+ }.transform_keys(&:to_s) )
11
+ }
12
+
13
+ return if defined? PERFORMANCE
14
+ $stdout.puts "F:#{Fiber.current.__id__} : T:#{Thread.current.__id__} : A:#{self.__id__} : #{msg}"
15
+ # LOGGER.debug :fiber_pool, msg
16
+ end
17
+
18
+
19
+
5
20
  class FiberConnectionPool < Sequel::ConnectionPool
6
21
  VALIDATION_TIMEOUT = 20
7
22
  POOL_SIZE = 10
8
23
 
9
- def log(msg)
10
- otl_current_span{ |span|
11
- span.add_event("FiberPool", attributes: {
12
- F: Fiber.current.__id__, T: Thread.current.__id__, A: self.__id__,
13
- message: msg
14
- }.transform_keys(&:to_s) )
15
- }
16
-
17
- return if defined? PERFORMANCE
18
- $stdout.puts "F:#{Fiber.current.__id__} : T:#{Thread.current.__id__} : A:#{self.__id__} : #{msg}"
19
- # LOGGER.debug :fiber_pool, msg
20
- end
21
-
22
24
  def initialize(db, opts = OPTS)
23
25
  otl_span "FiberConnectionPool.initialize" do |span|
24
26
  super
25
27
  @allocator = ->() {
26
28
  make_new(:default).tap { |conn|
27
- log "new connection (fiber pool) #{conn}"
29
+ $local_log["new connection (fiber pool) #{conn}"]
28
30
  }
29
31
  }
30
32
  @stock = []
@@ -44,7 +46,7 @@ class FiberConnectionPool < Sequel::ConnectionPool
44
46
 
45
47
  def hold(_server = nil)
46
48
  return yield @acquired[Fiber.current] if @acquired[Fiber.current] # protect from recursion
47
- log "hold in (fiber pool: #{__id__}) #{@stock.map{_1.__id__}}"
49
+ $local_log["hold in (fiber pool: #{__id__}) #{@stock.map{_1.__id__}}"]
48
50
  fiber = Fiber.current
49
51
  try_count = 2
50
52
 
@@ -60,19 +62,19 @@ class FiberConnectionPool < Sequel::ConnectionPool
60
62
  yield @acquired[fiber]
61
63
 
62
64
  rescue Sequel::DatabaseDisconnectError => e
63
- log "remove connection (fiber pool) retry(#{try_count})"
65
+ $local_log["remove connection (fiber pool) retry(#{try_count})"]
64
66
  @acquired.delete(fiber)
65
67
  (try_count -=1) < 0 ? raise : retry
66
68
 
67
69
  rescue =>e
68
70
  $stdout.puts e.message
69
71
  $stdout.puts e.backtrace[0..10].join "\n"
70
- log 'remove connection (fiber pool) give up'
72
+ $local_log['remove connection (fiber pool) give up']
71
73
  @acquired.delete(fiber)
72
74
  raise
73
75
  ensure
74
76
  @stock.push @acquired.delete(fiber) if @acquired[fiber]
75
- log "hold out (fiber pool: #{__id__}) #{@stock.map{_1.__id__}}"
77
+ $local_log["hold out (fiber pool: #{__id__}) #{@stock.map{_1.__id__}}"]
76
78
  end
77
79
  end
78
80
 
@@ -81,7 +83,7 @@ class FiberConnectionPool < Sequel::ConnectionPool
81
83
  # def preconnect(_concurrent = false) = :unimplemented
82
84
  def disconnect(symbol)
83
85
  until @stock.empty?
84
- log 'disconnect connection (fiber pool)'
86
+ $local_log['disconnect connection (fiber pool)']
85
87
  @stock.shift.close
86
88
  end
87
89
  end
@@ -100,10 +102,10 @@ require 'sequel/adapters/postgres'
100
102
  class Sequel::Postgres::Adapter
101
103
  def execute_query(sql, args)
102
104
  $stdout.puts "F:#{Fiber.current.__id__} : T:#{Thread.current.__id__} : A:#{self.__id__} : #{sql[0..60]}" unless defined? PERFORMANCE
103
- log "query: #{sql.slice(0, 60)}"
105
+ $local_log["query: #{sql.slice(0, 60)}"]
104
106
  @db.log_connection_yield(sql, self, args){args ? async_exec_params(sql, args) : async_exec(sql)}
105
107
  rescue => e
106
- log "Error: #{e.message}"
108
+ $local_log["Error: #{e.message}"]
107
109
  $stdout.puts e.message
108
110
  raise
109
111
  end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module StackServiceBase
2
2
  class Base
3
- VERSION = '0.0.19'
3
+ VERSION = '0.0.21'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack-service-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-06-25 00:00:00.000000000 Z
11
+ date: 2025-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack